<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kah - The Developer</title>
	<atom:link href="http://kahdev.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kahdev.wordpress.com</link>
	<description>The world of development ...</description>
	<lastBuildDate>Tue, 27 Oct 2009 11:51:00 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='kahdev.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/a55f38dfa461d2a5c43fe922624b963d?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Kah - The Developer</title>
		<link>http://kahdev.wordpress.com</link>
	</image>
			<item>
		<title>Starting with Tables in OpenOffice Base</title>
		<link>http://kahdev.wordpress.com/2009/10/27/starting-with-tables-in-openoffice-base/</link>
		<comments>http://kahdev.wordpress.com/2009/10/27/starting-with-tables-in-openoffice-base/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 11:51:00 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[OpenOffice]]></category>
		<category><![CDATA[Base]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=180</guid>
		<description><![CDATA[When you create a new database using OpenOffice base, you will need to setup one or more tables to store and organise your data. If you are already familar with other database systems, like MySQL or PostgreSQL, you already how to use tables and should be able to do this part yourself. If you wish, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=180&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When you create a new database using OpenOffice base, you will need to setup one or more tables to store and organise your data. If you are already familar with other database systems, like <a href="http://www.mysql.com">MySQL</a> or <a href="http://www.postgresql.org">PostgreSQL</a>, you already how to use tables and should be able to do this part yourself. If you wish, you can always use the wizard to create a table.<span id="more-180"></span> However, I usually prefer to create it &#8220;manually&#8221; (note, there is nothing wrong with using the wizard, if you prefer to use it). To start creating tables, select <strong><em>Tables</em></strong> and then <strong><em>Create Table In Design View</em></strong>.</p>
<p><img class="aligncenter size-full wp-image-179" title="Initial Screen" src="http://kahdev.files.wordpress.com/2009/10/shot1.jpg?w=454&#038;h=340" alt="Initial Screen" width="454" height="340" /></p>
<p>This should bring up an empty table.</p>
<div id="attachment_181" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-181" title="Table Editor" src="http://kahdev.files.wordpress.com/2009/10/shot2.jpg?w=480&#038;h=311" alt="Table Editor" width="480" height="311" /><p class="wp-caption-text">The table for editing your own data table.</p></div>
<p style="text-align:center;">
<p>To fill in the table, you first have to know which information you wish to store in the table. For example, if the database is storing information about the members of a club, it could be storing information about a person and for each person, you want to store their first and last names, their date of birth and their contact number. Each row in the table corresponds to one of this attributes. They must be assigned a name and a type. The type determines what kind of information may be stored in the field. For example, a name could be a text and the date of birth is a date. Once you have decided all of this, filling the table should be straight forward. Here is a table containing the information in the example just mentioned:</p>
<div id="attachment_182" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-182" title="Data Table Example" src="http://kahdev.files.wordpress.com/2009/10/shot3.jpg?w=480&#038;h=288" alt="Data Table Example" width="480" height="288" /><p class="wp-caption-text">A data table for storing a person&#39;s details.</p></div>
<p>The field properties at the bottom provides options that may be specific to a field. The fields in the properties should be self explanatory and there is a short description of the fields in the bottom right corner, if you require it.</p>
<p>When you save the new table for the first time, you will be asked to name the table and, if you have not selected a primary key, whether you want primary key to be automatically created or not. The primary key will <span style="text-decoration:underline;">uniquely</span> identify the each row in the table (or each &#8220;record&#8221; you make). For this reason, the data in the primary key column can <strong>NOT</strong> contain dulplicates. If you let OpenOffice create a primary key for you, it will insert an <strong><em>ID</em></strong> column that is simply an <strong><em>Integer</em></strong> field that autoincrements. If prefer, you can select your own primary key. To make a field the primary key, right click on the cell next to the next to the field name to bring up the context menu and select &#8220;primary key&#8221;. The primary key is marked with the key icon.</p>
<div id="attachment_183" class="wp-caption aligncenter" style="width: 476px"><img class="size-full wp-image-183" title="Single primary key." src="http://kahdev.files.wordpress.com/2009/10/shot4.jpg?w=466&#038;h=151" alt="Single primary key." width="466" height="151" /><p class="wp-caption-text">Making a field the primary key. The primary key field is then marked with a key.</p></div>
<p>If you have a combination of fields that, when combined, form unique a <strong>combination</strong> you can also make the combination the primary key. For example, consider a table of people that contains the first and last names of each person. Now, lets say the first entry in the table is John Smith (ie John is entered as the first name and Smith as the last name). The next entry could be John Doe or Wayne Smith, since the last name and first names, respectively, do match the any of the other entries. However, there can not be another John Smit entry in the table. To make a combination of fields a primary key, select the fields before right clicking to make them the primary key.</p>
<p><img class="aligncenter size-full wp-image-184" title="Combination Primary Key" src="http://kahdev.files.wordpress.com/2009/10/shot5.jpg?w=466&#038;h=151" alt="Combination Primary Key" width="466" height="151" /></p>
<p>Once the table has been set up, you can reopen the table to start filling the database with data. Back on the database screen, open the table where you want to insert the data. Simply enter the data as you would normally do for a spreadsheet.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=180&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/10/27/starting-with-tables-in-openoffice-base/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/10/shot1.jpg" medium="image">
			<media:title type="html">Initial Screen</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/10/shot2.jpg" medium="image">
			<media:title type="html">Table Editor</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/10/shot3.jpg" medium="image">
			<media:title type="html">Data Table Example</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/10/shot4.jpg" medium="image">
			<media:title type="html">Single primary key.</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/10/shot5.jpg" medium="image">
			<media:title type="html">Combination Primary Key</media:title>
		</media:content>
	</item>
		<item>
		<title>Formatting Source Code in HTML</title>
		<link>http://kahdev.wordpress.com/2009/08/18/formatting-source-code-in-html/</link>
		<comments>http://kahdev.wordpress.com/2009/08/18/formatting-source-code-in-html/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 14:43:40 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=164</guid>
		<description><![CDATA[If have you seen a number of my tutorials, you would have seen some nicely formatted sample code embedded within the page. Pastebins can host your code there are Javascripts that can also format your code. However, the WordPress service does not allow either of those options to be used. The only way I have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=164&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If have you seen a number of my tutorials, you would have seen some nicely formatted sample code embedded within the page. <a href="http://en.wikipedia.org/wiki/Pastebin">Pastebins</a> can host your code there are Javascripts that can also format your code. However, the <b>WordPress</b> service does not allow either of those options to be used. The only way I have been able to do so far has been to convert the code into an HTML code.</p>
<p><span id="more-164"></span></p>
<h2>Copy and Paste from Eclipse</h2>
<p>If you have been developing your code in <a href="http://www.eclipse.org">Eclipse</a>, you can actually copy and paste the code into a rich text editor (such as <a href="http://www.openoffice.org">OpenOffice</a>) and save it in HTML form. This will present the code in the same format as that presented in Eclipse. However, I find that using this method requires some extra editing on the generated HTML code, otherwise the results would looks something like this:</p>
<div><P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#3f5fbf"><FONT FACE="Monospace"><FONT SIZE="2">/**</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#3f5fbf"> <FONT FACE="Monospace"><FONT SIZE="2">*<br />
Sample class to demonstrate generated HTML formatting.</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#3f5fbf"> <FONT FACE="Monospace"><FONT SIZE="2">*<br />
</FONT></FONT></FONT><br />
</P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#3f5fbf"> <FONT FACE="Monospace"><FONT SIZE="2">*<br />
</FONT><FONT COLOR="#7f9fbf"><B>@author</B></FONT><FONT COLOR="#3f5fbf"><br />
</FONT><FONT COLOR="#3f5fbf"><U>kah</U></FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#3f5fbf"> <FONT FACE="Monospace"><FONT SIZE="2">*/</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE="2"><FONT COLOR="#7f0055"><B>public</B></FONT><FONT COLOR="#000000"><br />
</FONT><FONT COLOR="#7f0055"><B>class</B></FONT><FONT COLOR="#000000"><br />
HelloWorld {</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE="2"><FONT COLOR="#000000">	</FONT><FONT COLOR="#7f0055"><B>public</B></FONT><FONT COLOR="#000000"><br />
HelloWorld() {</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE="2"><FONT COLOR="#000000">		String<br />
message = </FONT><FONT COLOR="#2a00ff">&quot;Hello there!&quot;</FONT><FONT COLOR="#000000">;</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT FACE="Monospace"><FONT SIZE="2"><FONT COLOR="#000000">		System.</FONT><FONT COLOR="#0000c0"><I>out</I></FONT><FONT COLOR="#000000">.println(message);</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Monospace"><FONT SIZE="2">	}</FONT></FONT></FONT></P><br />
<P ALIGN="LEFT" STYLE="margin-bottom: 0cm"><FONT COLOR="#000000"><FONT FACE="Monospace"><FONT SIZE="2">}</FONT></FONT></FONT></P></div>
<p>No changes to the original HTML were made here. A fair amount of HTML editing is still required to get the nice format. The HTML was actually generated by saving copying into OpenOffice and then saving it as an HTML file. If you intend to use this method, it may be worth trying out other rich text editors.<br />
</p>
<h2>Generate the HTML using Vim</h2>
<p>My preferred method is actually to simply use <a href="http://www.vim.org">Vim</a> to perform the conversion. <a href="http://www.vim.org">Vim</a> is available for Linux, Macs and Windows. If you are using the graphical version of Vim, open up your source file and click on <b>syntax</b> -&gt; <b>Convert to HTML</b>. If you running it in a terminal, use the following ex command instead:</p>
<p><font face="monospace">:TOhtml</font></p>
<p>This will split the editor horizontally and add the HTML code at the top.</p>
<div id="attachment_172" class="wp-caption aligncenter" style="width: 472px"><img class="size-full wp-image-172" title="vim_screenshot" src="http://kahdev.files.wordpress.com/2009/08/vim_screenshot.png?w=462&#038;h=403" alt="Vim with generatd HTML" width="462" height="403" /><p class="wp-caption-text">Vim with generatd HTML</p></div>
<p>Here is a sample of the formatting produced by the conversion:</p>
<p><font face="monospace"><br />
<font color="#a52a2a">&nbsp;1 </font><font color="#0000ff">/**</font><br />
<font color="#a52a2a">&nbsp;2 </font><font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Sample class to demonstrate generated HTML formatting.</font><br />
<font color="#a52a2a">&nbsp;3 </font><font color="#0000ff">&nbsp;* </font><br />
<font color="#a52a2a">&nbsp;4 </font><font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;kah</font><br />
<font color="#a52a2a">&nbsp;5 </font><font color="#0000ff">&nbsp;*/</font><br />
<font color="#a52a2a">&nbsp;6 </font><font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;HelloWorld {<br />
<font color="#a52a2a">&nbsp;7 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;HelloWorld()&nbsp;{<br />
<font color="#a52a2a">&nbsp;8 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String message = <font color="#ff00ff">&quot;Hello there!&quot;</font>;<br />
<font color="#a52a2a">&nbsp;9 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(message);<br />
<font color="#a52a2a">10 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#a52a2a">11 </font>}<br />
</font></p>
<p>The results from this are much better and a lot less editing necessary! Here are a few more tips for using this method:</p>
<ol>
<li>I have found that when I copy and paste the generated HTML into my blog post, on <b>WordPress</b>, the system would sometimes adds empty lines between each line of code. I removed this extra lines by removing the <b>&lt;br&gt;</b> tags from the HTML code.</li>
<li>If you want to add line numbering to your generated code, you need to turn on numbering first. To turn it on, execute the following ex command:
<p>    <font face="monospace">:set nu</font></li>
<li> Finally, the colour scheme used in the generated HTML code will follow the colorscheme that Vim is set to. In other words, you can control the colour scheme used by syntax highlighting by setting Vim to the desired colour scheme before you generate the HTML code. If you are using the graphical version, you can find some of the available colour schemes by going to <b>Edit</b> -&gt; <b>Color Scheme</b>.</li>
</ol>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=164&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/08/18/formatting-source-code-in-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/08/vim_screenshot.png" medium="image">
			<media:title type="html">vim_screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>Controlling UI Components using JGoodies Binding</title>
		<link>http://kahdev.wordpress.com/2009/07/07/controlling-ui-components-using-jgoodies-binding/</link>
		<comments>http://kahdev.wordpress.com/2009/07/07/controlling-ui-components-using-jgoodies-binding/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 12:31:39 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Bindings]]></category>
		<category><![CDATA[JGoodies]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JGoodies Binding]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=150</guid>
		<description><![CDATA[In Binding with JGoodies Binding, the binding library from JGoodies was introduced with a relatively simple example. The binding framework can also be used to automatically enable or disable user interface components depending on some condition.
A model is used to notify when the component should be enabled or disabled. This is a relatively simple model. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=150&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In <a href="http://kahdev.wordpress.com/2009/04/29/binding-with-jgoodies-binding/">Binding with JGoodies Binding</a>, the binding library from <a href="http://www.jgoodies.com">JGoodies</a> was introduced with a relatively simple example. The binding framework can also be used to automatically enable or disable user interface components depending on some condition.</p>
<p>A model is used to notify when the component should be enabled or disabled. This is a relatively simple model. It only needs to notify the library when the component should be enabled or disabled. I&#8217;ve called the model <i>Allowance</i>, as it is designed to notify when a feature or function is <b>allowed</b> to be used or performed rather than when something should be enabled or disabled. The code for the model is presented here:</p>
<p style="padding-left:30px;"><font face="monospace" color="#000000"><font color="#804040">&nbsp;1 </font><font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;Allowance <font color="#2e8b57"><b>extends</b></font>&nbsp;Model {<br />
<font color="#804040">&nbsp;2 </font><br />
<font color="#804040">&nbsp;3 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;<font color="#2e8b57"><b>long</b></font>&nbsp;<br />
<font color="#804040">&nbsp;4 </font>&nbsp;&nbsp;&nbsp;&nbsp;serialVersionUID = <font color="#ff00ff">1L</font>;<br />
<font color="#804040">&nbsp;5 </font>&nbsp;&nbsp;<br />
<font color="#804040">&nbsp;6 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;String<br />
<font color="#804040">&nbsp;7 </font>&nbsp;&nbsp;&nbsp;&nbsp;PROPERTY_ALLOWANCE = <font color="#ff00ff">&quot;allowed&quot;</font>;<br />
<font color="#804040">&nbsp;8 </font><br />
<font color="#804040">&nbsp;9 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>boolean</b></font>&nbsp;allow = <font color="#ff00ff">false</font>;<br />
<font color="#804040">10 </font>&nbsp;&nbsp;<br />
<font color="#804040">11 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setAllowed(<font color="#2e8b57"><b>boolean</b></font>&nbsp;nowAllowed)&nbsp;<br />
<font color="#804040">12 </font>&nbsp;&nbsp;{<br />
<font color="#804040">13 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>boolean</b></font>&nbsp;oldAllowed = allow;<br />
<font color="#804040">14 </font>&nbsp;&nbsp;&nbsp;&nbsp;allow = nowAllowed;<br />
<font color="#804040">15 </font>&nbsp;&nbsp;&nbsp;&nbsp;firePropertyChange(PROPERTY_ALLOWANCE,<br />
<font color="#804040">16 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oldAllowed, allow);<br />
<font color="#804040">17 </font>&nbsp;&nbsp;}<br />
<font color="#804040">18 </font><br />
<font color="#804040">19 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>boolean</b></font>&nbsp;isAllowed()<br />
<font color="#804040">20 </font>&nbsp;&nbsp;{<br />
<font color="#804040">21 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>return</b></font>&nbsp;allow;<br />
<font color="#804040">22 </font>&nbsp;&nbsp;}<br />
<font color="#804040">23 </font>}<br />
</font></p>
<p>Next, the <b>Allowance</b> model needs to be bound to the UI component. In the previously mentioned tutorial, an editor for a book&apos;s subject and title was created and bound to a model for a book. Let&apos;s say that the title field will now be enabled only when a subject is selected and disabled at all other times. Models allows listeners to be attached to receive notification of changes to specific properties. Interested listeners must implement the <b>PropertyChangeListener</b> interface. Here is the corresponding block of code to implement this behaviour:</p>
<p style="padding-left:30px;"><font face="monospace" color="#000000"><font color="#2e8b57"><b>final</b></font>&nbsp;Allowance allowed = <font color="#804040"><b>new</b></font>&nbsp;Allowance();<br />
PropertyChangeListener allowanceUpdate =<br />
&nbsp;&nbsp;<font color="#804040"><b>new</b></font>&nbsp;PropertyChangeListener()&nbsp;{</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a020f0">@Override</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;propertyChange(PropertyChangeEvent evt)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>if</b></font>&nbsp;(!evt.getNewValue().equals(<font color="#ff00ff">&quot;none&quot;</font>))&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allowed.setAllowed(<font color="#ff00ff">true</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <font color="#804040"><b>else</b></font>&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allowed.setAllowed(<font color="#ff00ff">false</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;};<br />
</font></p>
<p>The listener simply receives an event that contains information on the source of the event (i.e. the object with the changed property) and the old and new values of the property.</p>
<p>To be of any use, the listener has to be attached to our model. There are a few options on how this could be done. The listener can be directly attached to our model or indirectly via the same presentation model used in creating the editor. Generally, I recommend going through presentation model, as that would allow you to change the instance being edited much more easily. The listener requires knowledge of changes to the subject only. The binding library allows listeners to be notified of only changes to the subject. To attach the listener:</p>
<p style="padding-left:30px;"><font face="monospace" color="#000000">presentation.getModel(Book.PROPERTY_TOPIC).<br />
&nbsp;&nbsp;addPropertyChangeListener(allowanceUpdate);<br />
</font></p>
<p>The call to <b>getModel()</b> will retrieve the value model for the subject property of the book model. When you want to change the instance of the model that is being edited, you can use the presentation model&apos;s <b>setBean()</b> to load the new instance. If the listener had been attached to the our object, we would have to move the listener to the new instance ourselves. This is why I prefer going through the presentation model.</p>
<p>Finally, the allowance model needs to somehow be connected to the UI component. The line to do this:</p>
<p style="padding-left:30px;"><font face="monospace" color="#000000">PropertyConnector connection =<br />
&nbsp;&nbsp;PropertyConnector.connect(nameField, &quot;enable&quot;,<br />
&nbsp;&nbsp;&nbsp;&nbsp;allowed, Allowance.PROPERTY_ALLOWANCE);<br />
allowed.setAllowed(false);<br />
connection.updateProperty1();<br />
</font></p>
<p>The <b>PropertyConnector</b> will automatically listen for changes to the <b>Allowance</b> and update the &quot;enable&quot; property of the component. Note that the &quot;enable&quot; property could have also been substituted for &quot;visible&quot; to have it change its visibility or &quoy;editable&quot; to change whether it is editable or not. Using any of these properties will effectively control whether the user is able to edit the contents of the text field. There are also a few other properties that can be controlled in this way, such as &quot;focusable&quot; and &quot;opaque&quot;. Files from this tutorial are downloadable from <a href="http://www.box.net/shared/5akh3b7r4v">here</a></p>
<p>While in the example an <b>Allowance</b> model was created for the purpose of modelling when a component can be used or not, it should be noted that the binding library provides <b>ComponentValueModel</b> to control three of the properties &#8211; visible, editable and enabled. The model provides three separate methods for controlling the properties separately &#8211; <b>setEditable</b>, <b>setEnabled</b> and <b>setVisible</b>. Instead of using <b>PropertyConnector</b> to bind the model to the UI component, you should using <b>Binding.addComponentPropertyHandler</b> instead.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=150&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/07/07/controlling-ui-components-using-jgoodies-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting the Font in a View</title>
		<link>http://kahdev.wordpress.com/2009/06/24/setting-the-font-in-a-view/</link>
		<comments>http://kahdev.wordpress.com/2009/06/24/setting-the-font-in-a-view/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 14:26:44 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=138</guid>
		<description><![CDATA[Sometime ago, I was asked how to control the font used in a customised view. In the customised view, the onDraw method is overridden and had code looking like this:
 
Paint textPaint = new Paint();
textPaint.setColor(Color.BLACK);
canvas.drawText("Text to display", posX,
    posY, textPaint);
To change the font, Paint has a setTypeface method. This method takes in a Typeface [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=138&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometime ago, I was asked how to control the font used in a customised view. In the customised view, the <em>onDraw</em> method is overridden and had code looking like this:</p>
<p style="padding-left:30px;"><span style="font-family:courier new;font-size:10pt;"> </span></p>
<pre style="padding-left:30px;"><span style="font-family:courier new;font-size:10pt;"><span style="color:#000000;">Paint</span> <span style="color:#000000;">textPaint</span> <span style="color:#000000;">=</span> <span style="font-weight:bold;color:#7f0055;">new</span> <span style="color:#000000;">Paint();</span></span>
<span style="font-family:courier new;font-size:10pt;"><span style="color:#000000;">textPaint.setColor(Color.BLACK);</span></span>
<span style="font-family:courier new;font-size:10pt;"><span style="color:#000000;">canvas.drawText(</span><span style="color:#2a00ff;">"Text to display"</span><span style="color:#000000;">,</span> <span style="color:#000000;">posX,</span>
    <span style="color:#000000;">posY,</span> <span style="color:#000000;">textPaint);</span></span></pre>
<p>To change the font, <a href="http://developer.android.com/reference/android/graphics/Paint.html"><em>Paint</em></a> has a <a href="http://developer.android.com/reference/android/graphics/Paint.html#setTypeface%28android.graphics.Typeface%29"><em>setTypeface</em></a> method. This method takes in a <a href="http://developer.android.com/reference/android/graphics/Typeface.html"><em>Typeface</em></a> object, which determines which font is used. The <em>Typeface</em> class has a number of static methods to create the instance for us. If you want to use TrueType Font file, place the file in <em>assets</em> folder, like how this:</p>
<p><img class="aligncenter size-full wp-image-140" title="TTF file in the assets" src="http://kahdev.files.wordpress.com/2009/06/font_placement.jpg?w=185&#038;h=111" alt="TTF file in the assets" width="185" height="111" /></p>
<p>Now in the code, we can use the <a href="http://developer.android.com/reference/android/graphics/Typeface.html#createFromAsset%28android.content.res.AssetManager,%20java.lang.String%29"><em>createFromAsset</em></a> method to create the <em>Typeface</em> object and set the <em>Paint</em> to use it. With the additional lines, the code fragment now looks like this (the added lines are in <strong>bold</strong>):</p>
<pre style="padding-left:30px;"><span style="font-family:courier new;font-size:10pt;"><span style="color:#000000;">Paint</span> <span style="color:#000000;">textPaint</span> <span style="color:#000000;">=</span> <span style="font-weight:bold;color:#7f0055;">new</span> <span style="color:#000000;">Paint();</span>
<span style="color:#000000;">textPaint.setColor(Color.BLACK);</span>
<strong><span style="color:#000000;">Typeface</span> <span style="color:#000000;">font</span> <span style="color:#000000;">=</span> <span style="color:#000000;">Typeface.createFromAsset(</span>
    <span style="color:#000000;">getContext().getAssets(),</span> <span style="color:#2a00ff;">
    "fonts/androidnation.ttf"</span><span style="color:#000000;">);</span>
<span style="color:#000000;">textPaint.setTypeface(font);</span></strong>
<span style="color:#000000;">canvas.drawText(</span><span style="color:#2a00ff;">"Text to display"</span><span style="color:#000000;">,</span> <span style="color:#000000;">posX,</span> <span style="color:#000000;">posY,</span>
    <span style="color:#000000;">textPaint);</span></span></pre>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;"><em>Typeface</em> also has a few fonts that are already defined and can be loaded without having to additional font files. These fonts are defined as public constants in <em>Typeface</em> and they are listed in the <a href="http://developer.android.com/reference/android/graphics/Typeface.html">documentation for </a><a href="http://developer.android.com/reference/android/graphics/Typeface.html"><em>Typeface</em></a>. For example, to set the <em>Paint</em> to use the default bold font:</p>
<p style="padding-left:30px;"><span style="font-family:courier new;font-size:10pt;"><span style="color:#000000;">textPaint.setTypeface(Typeface.DEFAULT_BOLD);</span></span></p>
<p style="margin-bottom:0;">The other fonts defined accessible as constants from <em>Typeface</em> are serif, sans serif and monospace.</p>
<p style="margin-bottom:0;">The font of text inside a <a href="http://developer.android.com/reference/android/widget/TextView.html"><em>TextView</em></a> can also be changed using its <a href="http://developer.android.com/reference/android/widget/TextView.html#setTypeface%28android.graphics.Typeface%29"><em>setTypeface</em></a> method. Like the one for <em>Paint</em>, it also takes in a <em>Typeface</em> as an argument. If the <em>TextView</em> is being specified in a layout XML file, the font can be changed using the <a href="http://developer.android.com/reference/android/R.styleable.html#TextAppearance_typeface"><em>android:typeface</em></a> attribute. For example.</p>
<pre style="padding-left:30px;"><span style="font-family:courier new;font-size:10pt;"><span style="color:#008080;">&lt;</span><span style="color:#3f7f7f;">TextView</span> <span style="color:#7f007f;">android:id</span>=<span style="font-style:italic;color:#2a00ff;">"@+id/TextView01"</span>
    <span style="color:#7f007f;">android:layout_width</span>=<span style="font-style:italic;color:#2a00ff;">"wrap_content"</span>
    <span style="color:#7f007f;">android:layout_height</span>=<span style="font-style:italic;color:#2a00ff;">"wrap_content"</span>
    <span style="color:#7f007f;">android:text</span>=<span style="font-style:italic;color:#2a00ff;">"Customised Font"</span>
    <strong><span style="color:#7f007f;">android:typeface</span>=<span style="font-style:italic;color:#2a00ff;">"monospace"</span></strong> <span style="color:#008080;">/&gt;</span></span></pre>
<p>However, the fonts must be either normal, sans, serif or monospace.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=138&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/06/24/setting-the-font-in-a-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/06/font_placement.jpg" medium="image">
			<media:title type="html">TTF file in the assets</media:title>
		</media:content>
	</item>
		<item>
		<title>Manage your Finances with GnuCash</title>
		<link>http://kahdev.wordpress.com/2009/06/23/manage-your-finances-with-gnucash/</link>
		<comments>http://kahdev.wordpress.com/2009/06/23/manage-your-finances-with-gnucash/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:10:07 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Finance]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=131</guid>
		<description><![CDATA[
I have been GnuCash to help manage my finances for a while now. If used correctly, it is useful tool for tracking your finances and planning for those big ticket purchases. You do not require a lot of knowledge of accounting to use this software – just enough discipline to keep the data up to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=131&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		H2 { margin-bottom: 0.21cm } 		H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic } 		H2.cjk { font-family: "MS Mincho"; font-size: 14pt; font-style: italic } 		H2.ctl { font-size: 14pt; font-style: italic } --></p>
<p style="margin-bottom:0;"><span style="font-style:normal;">I have been </span><a href="http://www.gnucash.org"><em>GnuCash</em></a> to help manage my finances for a while now. If used correctly, it is useful tool for tracking your finances and planning for those big ticket purchases. You do not require a lot of knowledge of accounting to use this software – just enough discipline to keep the data up to date! It is also an open source software. This tutorial provide a quick introduction to some of its basic functions.</p>
<p style="margin-bottom:0;">
<h2>Setup the Accounts</h2>
<p style="margin-bottom:0;">All assets, expenses, etc. are organised into a hierarchy of accounts. When you create a new file for the first time, you can use a wizard to set up some default accounts and custom them later. To begin, create your first accounts by selecting <em>File</em> → <em>New</em> → <em>New File</em>. A <em>New Account Heirarchy Setup</em> druid (or a wizard) will guide you through to setting up the first set of accounts. Feel free to go through the druid to setup the first accounts. Once the wizard finishes, you&#8217;ll be brought to the accounts page.</p>
<p style="margin-bottom:0;"><img class="aligncenter size-full wp-image-128" title="Accounts Page" src="http://kahdev.files.wordpress.com/2009/06/accounts.jpg?w=480&#038;h=364" alt="Accounts Page" width="480" height="364" /></p>
<p style="margin-bottom:0;">Here, you should review which accounts have been setup, as the hierarchy of accounts also represents the breakdown of your asserts, income, expenses, etc. You should check that the accounts are broken down to a level that you are happy with. For example, if you have multiple savings account you may wish to have separate subaccounts for each one instead of having just one account to represent all of them.</p>
<p style="margin-bottom:0;">
<h2>Tracking your Accounts</h2>
<p style="margin-bottom:0;">When you create a new account, the dialog will have an <em>Opening Balance</em> tab for you to enter the opening amount.</p>
<p style="margin-bottom:0;"><img class="aligncenter size-full wp-image-129" title="Opening Balance Tab" src="http://kahdev.files.wordpress.com/2009/06/opening_balance_input.jpg?w=418&#038;h=487" alt="Opening Balance Tab" width="418" height="487" /></p>
<p style="margin-bottom:0;">If you did not enter an opening balance, you can still enter this manually.  First, open up the account that you want to enter the initial balance for. An empty accounts page will looks something like this:</p>
<p><img class="aligncenter size-full wp-image-130" title="Transactions For an Account" src="http://kahdev.files.wordpress.com/2009/06/transactions.jpg?w=480&#038;h=221" alt="Transactions For an Account" width="480" height="221" /></p>
<p style="margin-bottom:0;">The transfer column is the account that the amount is taken from. All transactions must result in a transfer to or from another account. If you leave the column blank, <em>GnuCash</em> will assign a default account. For opening balances, <em>GnuCash</em> would have suggested using a separate equity account. After entering your opening balance, you can open the account that you transferred from. You should be able to find a corresponding entry back to your account. Each time you enter a transaction into an account, there will always be a corresponding entry in the account that you transfer from or to. When you return to the main account page, the amounts in each account will be updated to account for the transactions. The totals under each account reveal how much is in an account or how much has been spent, etc.</p>
<p style="margin-bottom:0;">
<h2>Recurring Transactions</h2>
<p><em>GnuCash</em> allows can automatically enter recurring transactions. There are a couple of ways to setup the transactions. The scheduled transactions editor accessed through <em>Actions</em> → <em>Scheduled Transactions</em> → <em>Scheduled Transaction Editor.</em> You should be able to go through each of the options and fill in the fields without much trouble. Once you have created your scheduled transaction, it should be added to the list of transactions on the <em>Scheduled Transactions</em> page. You can also create scheduled transactions from an accounts page by right clicking when you are entering a new transaction.</p>
<h2>Generating Reports</h2>
<p>The data collected by <em>GnuCash</em> can be displayed in many different ways. Firstly, there is the main accounts page that provides a snapshot of how much is in each account or how much you have spent in each category. <em>Expense Piechart</em> and <em>Expense Barchart</em> reports available under <em>Income and Expenses</em> are especially useful if you are trying to find ways at reducing spending. If you are also wondering how much you are worth over a period of time, you should check out the <em>Net Work Barchart</em> under <em>Assests &amp; Liabilities</em>. However, it is important to note that the reliability of the information provided by these reports depends on how well you manage to keep the data up to date.</p>
<p>This covers the some of the features that you would most likely use in managing your personal finances. However, there are many more features not yet covered. If you run a business, it also has features for employee salaries, invoices and bills. If you hold shares, it also has features for entering purchased stocks and retrieving the latest prices. There are simply too many features to cover in this tutorial! If you are interested in using the other functions, the <em>Tutorial and Concepts Guide </em>under <em>Help</em> will provide most of the information that you require.</p>
<p style="margin-bottom:0;">
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=131&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/06/23/manage-your-finances-with-gnucash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/06/accounts.jpg" medium="image">
			<media:title type="html">Accounts Page</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/06/opening_balance_input.jpg" medium="image">
			<media:title type="html">Opening Balance Tab</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/06/transactions.jpg" medium="image">
			<media:title type="html">Transactions For an Account</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding with JGoodies Binding</title>
		<link>http://kahdev.wordpress.com/2009/04/29/binding-with-jgoodies-binding/</link>
		<comments>http://kahdev.wordpress.com/2009/04/29/binding-with-jgoodies-binding/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:10:06 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Bindings]]></category>
		<category><![CDATA[JGoodies]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JGoodies Binding]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=123</guid>
		<description><![CDATA[The binding framework allows you to write classes that represents model completely independent of the user interface. The classes are bound to the user interface and are updated as the user interface enters information. The frame is based on the presentation pattern, described by Martin Fowler. 
The framework already provides a Model class. Classes containing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=123&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><P>The binding framework allows you to write classes that represents model completely independent of the user interface. The classes are bound to the user interface and are updated as the user interface enters information. The frame is based on the <A HREF="http://martinfowler.com/eaaDev/PresentationModel.html">presentation pattern</A>, described by Martin Fowler. </P></p>
<p><P STYLE="margin-bottom: 0cm">The framework already provides a <b>Model</b> class. Classes containing attributes that are editable on the user interface would be a subclass of this. It adds functionality to notify of events. By default, the frame assumes that the used naming conventions for the properties, accessors and mutator methods follow the same pattern as suggested in the <A HREF="http://java.sun.com/javase/technologies/desktop/javabeans/docs/spec.html">Java beans specification</A>. For the models that I create, I provide the property as a public constant within the model. The mutator code also need to call the model&#8217;s firePropertyChange method to notify listeners of a change to the property. For example, a model for a book could be the following:</P></p>
<p><font face="monospace"><span style="color:rgb(0,0,0);">&#8230;</span><br />
<span style="font-weight:bold;color:rgb(127,0,85);">public</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">class</span>&nbsp;<span style="color:rgb(0,0,0);">Book</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">extends</span>&nbsp;<span style="color:rgb(0,0,0);">Model</span>&nbsp;<br />
<span style="color:rgb(0,0,0);">{</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">/**</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="color:rgb(63,95,191);">References</span>&nbsp;<span style="color:rgb(63,95,191);">to</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">properties</span>&nbsp;<span style="color:rgb(63,95,191);">for</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">model.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*/</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">public</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">static</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">final</span>&nbsp;<span style="color:rgb(0,0,0);">String</span>&nbsp;<span style="color:rgb(0,0,0);">PROPERTY_TITLE</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(42,0,255);">&quot;title&quot;</span><span style="color:rgb(0,0,0);">;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">/**</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="color:rgb(63,95,191);">Keeps</span>&nbsp;<span style="color:rgb(63,95,191);">track</span>&nbsp;<span style="color:rgb(63,95,191);">of</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">title</span>&nbsp;<span style="color:rgb(63,95,191);">of</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">book.</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*/</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">private</span>&nbsp;<span style="color:rgb(0,0,0);">String</span>&nbsp;<span style="color:rgb(0,0,0);">title</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(42,0,255);">&quot;&nbsp;&quot;</span><span style="color:rgb(0,0,0);">;</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">/**</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="color:rgb(63,95,191);">Changes</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">title</span>&nbsp;<span style="color:rgb(63,95,191);">of</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">book.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="font-weight:bold;color:rgb(127,159,191);">@param</span>&nbsp;<span style="color:rgb(63,95,191);">newTitle</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">The</span>&nbsp;<span style="color:rgb(63,95,191);">new</span>&nbsp;<span style="color:rgb(63,95,191);">title</span>&nbsp;<span style="color:rgb(63,95,191);">for</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">book.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*/</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">public</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">void</span>&nbsp;<span style="color:rgb(0,0,0);">setTitle(String</span>&nbsp;<span style="color:rgb(0,0,0);">newTitle)</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">{</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">String</span>&nbsp;<span style="color:rgb(0,0,0);">oldTitle</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">title;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">title</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">newTitle;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">firePropertyChange(PROPERTY_TITLE,</span>&nbsp;<span style="color:rgb(0,0,0);">oldTitle,</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">newTitle);</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">}</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">/**</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="font-weight:bold;color:rgb(127,159,191);">@return</span>&nbsp;<span style="color:rgb(63,95,191);">The</span>&nbsp;<span style="color:rgb(63,95,191);">title</span>&nbsp;<span style="color:rgb(63,95,191);">of</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">book.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*/</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">public</span>&nbsp;<span style="color:rgb(0,0,0);">String</span>&nbsp;<span style="color:rgb(0,0,0);">getTitle()</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">{</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">return</span>&nbsp;<span style="color:rgb(0,0,0);">title;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">}</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span><br />
<span style="color:rgb(0,0,0);">}</span></font></p>
<p>For creating the user interface components that will be editing the model, the <b>PresentationModel</b> is created for the object. The <b>PresentationModel</b> provides a representation of the user interface. The framework also supplies a <b>BasicComponentFactory</b> that you can use to create the components. The factory will also bind the component to the appropriate attribute. The methods that create text fields require a value model as one of its paramters. The value model is what is actually updated when the user makes changes in the component and it should be retrieved from the <b>PresentationModel</b> using its <b>getModel</b> method. For example, to create a text field for entering the title of a book:</p>
<p><span style="font-family:courier new;font-size:10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">final</span>&nbsp;<span style="color:rgb(0,0,0);">Book</span>&nbsp;<span style="color:rgb(0,0,0);">subject</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">new</span>&nbsp;<span style="color:rgb(0,0,0);">Book();</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">final</span>&nbsp;<span style="color:rgb(0,0,0);">PresentationModel&lt;Book&gt;</span>&nbsp;<span style="color:rgb(0,0,0);">presentation</span>&nbsp;<span style="color:rgb(0,0,0);">=</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">new</span>&nbsp;<span style="color:rgb(0,0,0);">PresentationModel&lt;Book&gt;(subject);</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">JTextField</span>&nbsp;<span style="color:rgb(0,0,0);">nameField</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">BasicComponentFactory.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">createTextField(presentation.getModel(</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">Book.PROPERTY_TITLE),</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">false</span><span style="color:rgb(0,0,0);">);</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></span></p>
<p>The third parameter, which is set to <b>false</b> will cause the bounded instance to be updated as the user makes changes in the text field. Setting it to <b>true</b> will result in the changes being made only when the field loses focus instead. </p>
<p>In the case of list selection fields, such as a <b>JList</b> and <b>JComboBox</b>, the required model is a <b>SelectionInList</b>. <b>SelectionInList</b> provides the functionality for tracking changes in the selection. Setting up a <b>SelectionInList</b> might require a few different calls. </p>
<p><font face="monospace">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">public</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">static</span>&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">final</span>&nbsp;<span style="color:rgb(0,0,0);">String</span>&nbsp;<span style="color:rgb(0,0,0);">TOPICS[]</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">{</span><span style="color:rgb(42,0,255);">&quot;science&quot;</span><span style="color:rgb(0,0,0);">,</span>&nbsp;<span style="color:rgb(42,0,255);">&quot;history&quot;</span><span style="color:rgb(0,0,0);">,</span>&nbsp;<span style="color:rgb(42,0,255);">&quot;arts&quot;</span><span style="color:rgb(0,0,0);">};</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">SelectionInList&lt;String&gt;</span>&nbsp;<span style="color:rgb(0,0,0);">topicSelect</span>&nbsp;<span style="color:rgb(0,0,0);">=</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;color:rgb(127,0,85);">new</span>&nbsp;<span style="color:rgb(0,0,0);">SelectionInList&lt;String&gt;(TOPICS);</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">/**</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="color:rgb(63,95,191);">Set</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">presentation</span>&nbsp;<span style="color:rgb(63,95,191);">model</span>&nbsp;<span style="color:rgb(63,95,191);">as</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">model</span>&nbsp;<span style="color:rgb(63,95,191);">that</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*</span>&nbsp;<span style="color:rgb(63,95,191);">holds</span>&nbsp;<span style="color:rgb(63,95,191);">the</span>&nbsp;<span style="color:rgb(63,95,191);">selected</span>&nbsp;<span style="color:rgb(63,95,191);">value.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(63,95,191);">*/</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">topicSelect.setSelectionHolder(</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">presentation.getModel(</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">Book.PROPERTY_TOPIC));</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">JComboBox</span>&nbsp;<span style="color:rgb(0,0,0);">topicBox</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">BasicComponentFactory.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">createComboBox(topicSelect);</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></font></p>
<p>The <b>SelectionInList</b> class has a few different constructors that allow you to specify the set of possible options as a list or an array. The call to <b>setSelectionHolder</b> will make updates to the presention model as the selection of the value is changed.</p>
<p>The <b>BasicComponentFactory</b> can also create <b>JLabel</b> that displays the current value of an attribute in the model. The label gets updated as the value of the attribute changes.</p>
<p><span style="font-family:courier new;font-size:10pt;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">JLabel</span>&nbsp;<span style="color:rgb(0,0,0);">titleLabel</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">BasicComponentFactory.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">createLabel(presentation.getModel(</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">Book.PROPERTY_TITLE));</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">JLabel</span>&nbsp;<span style="color:rgb(0,0,0);">topicLabel</span>&nbsp;<span style="color:rgb(0,0,0);">=</span>&nbsp;<span style="color:rgb(0,0,0);">BasicComponentFactory.</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">createLabel(presentation.getModel(</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">Book.PROPERTY_TOPIC));</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:rgb(0,0,0);">&#8230;</span></span></p>
<p>Since the title property has been bound to the title text field, the <b>titleLabel</b> will be automatically updated when the user makes changes in the field. Similarly, topic property has been bound such that when the user changes its selection, it the <b>topicLabel</b> will be updated. If you wish to try out the examples from here, you can get the source code <a href="http://www.box.net/shared/8z6rushe9b">here</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/123/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/123/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/123/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=123&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/04/29/binding-with-jgoodies-binding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>
	</item>
		<item>
		<title>Merge Tracking with Subversion (pre 1.5.0)</title>
		<link>http://kahdev.wordpress.com/2009/04/07/merge-tracking-with-subversion-pre-150/</link>
		<comments>http://kahdev.wordpress.com/2009/04/07/merge-tracking-with-subversion-pre-150/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 13:08:26 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[merging]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svnmerge]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=109</guid>
		<description><![CDATA[Merge tracking was not made a standard feature of Subversion until version 1.5.0. For those using previous versions of Subversion, the svnmerge script provides this missing functionality.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=109&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-bottom:0;">Merge tracking is a feature of some revision control software. This feature remembers which merges have taken place, allowing you to later see what merges have been done and what else needs to be merged. The feature was not part of Subversion until version 1.5.0. However, not all projects are using the latest version of Subversion. Fortunately, for projects that are using older versions of subversion, there is still the <a href="http://subversion.tigris.org/tools_contrib.html#svnmerge_py">svnmerge</a> script. If your project is using the latest version of Subversion, it should already have similar functionality.</p>
<p style="margin-bottom:0;">
<h2><a name="1.1.Initialising Merge Tracking|outline"></a> Initialising Merge Tracking</h2>
<p style="margin-bottom:0;">To use the script, the branch should be made by using the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svn cp</span></span></span> command. The branch is usually created from trunk. Once the branch has been created and checked out, you must tell it to initialise your checkout <span style="text-decoration:none;"><strong>before</strong></span> making any changes. It is also important to execute the initalisation command at the <strong>top level</strong> directory of the branch. For example, lets say you check out the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">file:///repository/branch/example </span></span></span>to <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">/home/user/work</span></span></span> so that you now the contents of the branch is located in <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">/home/user/work/example</span></span></span>. Then you should change to the directory <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">/home/user/work/example</span></span></span> before executing the initialisation command:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge init</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">If you had already made any changes, you should receive an error similar to the following:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge: &#8220;.&#8221; has local modifications; it must be clean</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">If it was successful, you should now have a file <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-weight:normal;">svnmerge-commit-message.txt</span></span></span></span> in the directory. This file is used by the script to track the merges that are performed and can also be added to your repository so that you do not lose your merge tracking information if you delete your current checkout. The contents of the file is also human readable, so you can view it to see what has been merged.</p>
<p style="margin-bottom:0;">
<h2><a name="1.2.Finding Out What is Available for Merging|outline"></a> Finding Out What is Available for Merging</h2>
<p style="margin-bottom:0;">Now that the svnmerge has initialised merge tracking for the directory, you can find what changes from trunk need to be merged. The <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">avail</span></span></span> command will tell you which versions need to be merged. To view the log messages of the versions that need to be merged, you can simply use:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge avail &#8211;log</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">Omitting the “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">&#8211;log</span></span></span>” option will cause svnmerge to output just the revision numbers that need to be merged. The avail command also has the option “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">&#8211;diff</span></span></span>” to output the differences that need to be applied. If the initialisation was not properly done, you might receive the error:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge: no integration info available</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">Another message that you might receive is when you have created a branch from another branch. For example, if you create branch <em>b</em> from <em>a</em> and then <em>c</em> from <em>b</em><span style="font-style:normal;"> and you executed the command on branch </span><em>c</em><span style="font-style:normal;">, you would receive an error message that is </span><span style="font-style:normal;"><strong>similar</strong></span><span style="font-style:normal;"> to the following:</span></p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-style:normal;">svnmerge: multiple sources found. Explicit source argument (-S/&#8211;source) required.</span></span></span></span></span></span></span></p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-style:normal;">The merge sources available are:</span></span></span></span></span></span></span></p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="color:#6b0094;"> <span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-style:normal;">/trunk</span></span></span></span></span></span></span></p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="color:#6b0094;"> <span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-style:normal;">/branch/test</span></span></span></span></span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">The problem here is that svnmerge needs to know which of the parent branches to compare branch <em>c</em> with. As suggested in the message, using the “-S” option will tell svnmerge which branch to compare with.</p>
<p style="margin-bottom:0;">
<h2 style="page-break-inside:avoid;page-break-before:auto;">Merging to the Branch</h2>
<p style="margin-bottom:0;page-break-inside:avoid;">To perform the merge, you just have to use the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">merge</span></span></span> command, as follows:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-inside:avoid;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge merge</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">Once the command has been executed, the file <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-weight:normal;">svnmerge-commit-message.txt</span></span></span></span> will be updated with latest merge information. Note that because this file is updated when the script is called on to perform the merge, it will <strong>NOT</strong> detect any merges that you may have performed manually. Should you perform a merge without using svnmerge, you can try executing the merge with svnmerge to update the file. Alternatively, the merge command has a “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-style:normal;">-M</span></span></span></span>” command to record a merge without actually performing the merge. The merge command also allows you to specify the revisions that are merged. The option for this is “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">-r</span></span></span>”.</p>
<p style="margin-bottom:0;">
<h2>Merging Back to Parent</h2>
<p style="margin-bottom:0;">After you complete making changes on the branch, the script can also be used to merge the changes back to the parent branch. To do this, first change to the top level directory where the parent branch was checked out (similar to what was done in <a href="#1.1.Initialising Merge Tracking|outline">Initialising Merge Tracking</a>). Merge tracking needs to be initialised again. Beware that if you have a  <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;"><span style="font-weight:normal;">svnmerge-commit-message.txt</span></span></span></span> file in the directory, it will be overwritten. This path to the branch where the changes were made needs to also be specified, by using the following form of the initialising command:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge init [path to branch]</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">While staying in the same directory, execute the merge command to merge the changes back. Again, depending on the number of branches created from the parent, it may be necessary to specify the source branch if it complains about multiple sources (see <a href="#1.2.Finding Out What is Available for Merging|outline">Finding Out What is Available for Merging</a>). Note that when merging back to the parent, you do not have to execute the initialisation command at the location of the branch.</p>
<p style="margin-bottom:0;">
<h2>Preventing Specific Versions From Being Merged</h2>
<p style="margin-bottom:0;">After executing the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">avail</span></span></span> command, you might discover revisions that you might not want to merge. Revisions that should never be merged can be blocked using:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge block -r [revisions to block]</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">When you execute the merge again, you should find that the specified revisions are left out of the merge. Note that omitting the “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">-r</span></span></span>” option and the revisions will cause all available revisions to be added to the blocked list. This is also reflected in the output from executing the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">avail</span></span></span> command.</p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">If you later decide would like to make the revision available for merging later, you can use the <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">unblock</span></span></span> command.</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge unblock -r [revisions to unblock]</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">Again, omitting the “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">-r</span></span></span>” and listing the revisions altogether will unblock all revisions. Should you also forget which revisions were previously blocked, you can examine the property <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge-blocked</span></span></span>.</p>
<h2>Finding Out What has Been Merged</h2>
<p style="margin-bottom:0;">After having committed the merges, you might want to view the merges that have been previously performed. This viewable with the integrated command, which can be used like this:</p>
<p style="margin-left:1.5cm;margin-bottom:0;page-break-before:auto;"><span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svn integrated &#8211;log</span></span></span></p>
<p style="margin-bottom:0;">
<p style="margin-bottom:0;">Similar to the avail command, omitting the “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">&#8211;log</span></span></span>” option will cause to print out just revision numbers and “<span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">&#8211;diff</span></span></span>” can be used to view the differences. The versions that have been merged are also recorded in the property <span style="color:#6b0094;"><span style="font-family:Courier New,monospace;"><span style="font-size:small;">svnmerge-integrated</span></span></span>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=109&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/04/07/merge-tracking-with-subversion-pre-150/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding Selection Functionality to the Table View</title>
		<link>http://kahdev.wordpress.com/2009/03/29/adding-selection-functionality-to-the-table-view/</link>
		<comments>http://kahdev.wordpress.com/2009/03/29/adding-selection-functionality-to-the-table-view/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 07:22:32 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=106</guid>
		<description><![CDATA[Lately, I was looking at how to present data in a table format, where each row would be data from an object, and allow users to select a particular row. One way of doing it is writing a ListAdapter and using it with a ListView. However, the way I tried to do it was using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=106&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Lately, I was looking at how to present data in a table format, where each row would be data from an object, and allow users to select a particular row. One way of doing it is writing a <a href="http://developer.android.com/reference/android/widget/ListAdapter.html">ListAdapter</a> and using it with a <a href="http://developer.android.com/reference/android/widget/ListView.html">ListView</a>. However, the way I tried to do it was using the <a href="http://developer.android.com/reference/android/widget/TableLayout.html">TableLayout</a>. </p>
<p>Admittedly, using the <b>TableLayout</b> looked like it is more complicated than using the <b>ListView</b>, although I have yet to try using <b>ListView</b>. Using the <b>TableLayout</b>, the view is programatically created (without using an XML file). In order to implement this, the implementing class needs to keep track of a number of things.</p>
<p><font face="monospace"><br />
<font color="#804040">&nbsp;&nbsp;1 </font><font color="#a020f0">package</font>&nbsp;com.android.selectable;<br />
<font color="#804040">&nbsp;&nbsp;2 </font><br />
<font color="#804040">&nbsp;&nbsp;3 </font><font color="#a020f0">import</font>&nbsp;java.util.Collection;<br />
<font color="#804040">&nbsp;&nbsp;4 </font><br />
<font color="#804040">&nbsp;&nbsp;5 </font><font color="#a020f0">import</font>&nbsp;android.content.Context;<br />
<font color="#804040">&nbsp;&nbsp;6 </font><font color="#a020f0">import</font>&nbsp;android.graphics.Color;<br />
<font color="#804040">&nbsp;&nbsp;7 </font><font color="#a020f0">import</font>&nbsp;android.util.Log;<br />
<font color="#804040">&nbsp;&nbsp;8 </font><font color="#a020f0">import</font>&nbsp;android.view.MotionEvent;<br />
<font color="#804040">&nbsp;&nbsp;9 </font><font color="#a020f0">import</font>&nbsp;android.view.View;<br />
<font color="#804040">&nbsp;10 </font><font color="#a020f0">import</font>&nbsp;android.widget.TableLayout;<br />
<font color="#804040">&nbsp;11 </font><font color="#a020f0">import</font>&nbsp;android.widget.TableRow;<br />
<font color="#804040">&nbsp;12 </font><br />
<font color="#804040">&nbsp;13 </font><font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;14 </font><font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Manages the display of the watch list.</font><br />
<font color="#804040">&nbsp;15 </font><font color="#0000ff">&nbsp;*&nbsp;&nbsp;</font><br />
<font color="#804040">&nbsp;16 </font><font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;Kah</font><br />
<font color="#804040">&nbsp;17 </font><font color="#0000ff">&nbsp;*/</font><br />
<font color="#804040">&nbsp;18 </font><font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;ListDisplay&lt;T&gt;<br />
<font color="#804040">&nbsp;19 </font>{<br />
<font color="#804040">&nbsp;20 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;21 </font><font color="#0000ff">&nbsp;&nbsp;*</font><font color="#6a5acd">&nbsp;Reference to the list of stocks that are in the</font><br />
<font color="#804040">&nbsp;22 </font><font color="#0000ff">&nbsp;&nbsp;*</font><font color="#6a5acd">&nbsp;watch list.</font><br />
<font color="#804040">&nbsp;23 </font><font color="#0000ff">&nbsp;&nbsp;*/</font><br />
<font color="#804040">&nbsp;24 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;Collection&lt;T&gt; itemsCollection;<br />
<font color="#804040">&nbsp;25 </font>&nbsp;&nbsp;<br />
<font color="#804040">&nbsp;26 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;27 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Reference to the view that displays the watch </font><br />
<font color="#804040">&nbsp;28 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;list on the user interface.</font><font color="#0000ff">&nbsp;This needs to </font><br />
<font color="#804040">&nbsp;29 </font><font color="#0000ff">&nbsp;&nbsp; * inflated later, since the instance of the </font><br />
<font color="#804040">&nbsp;30 </font><font color="#0000ff">&nbsp;&nbsp; * layout inflater is required to create it.</font><br />
<font color="#804040">&nbsp;31 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">&nbsp;32 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;TableLayout display;<br />
<font color="#804040">&nbsp;33 </font><br />
<font color="#804040">&nbsp;34 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;Context appContext;<br />
<font color="#804040">&nbsp;35 </font><br />
<font color="#804040">&nbsp;36 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;DisplayAdapter&lt;T&gt; dataAdapter;<br />
<font color="#804040">&nbsp;37 </font><br />
<font color="#804040">&nbsp;38 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;SelectionReceiver&lt;T&gt; selectionObserver;<br />
<font color="#804040">&nbsp;39 </font>&nbsp;&nbsp;<br />
<font color="#804040">&nbsp;40 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;T highlighted;<br />
<font color="#804040">&nbsp;41 </font>&nbsp;&nbsp;<br />
</font></p>
<p>The <b>DisplayAdapter</b> is used to convert the objects into the data that gets displayed. A <b>SelectionReceiver</b> is notified when a item is selected by clicking on it.</p>
<p>The constructor creates the <b>TableLayout</b>, which may be set as the content view or may be added to another view.<br />
<font color="#804040">&nbsp;67 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;68 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Retrieves the display component to display the </font><br />
<font color="#804040">&nbsp;69 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;contents of the watch</font><br />
<font color="#804040">&nbsp;70 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;list on the user interface.</font><br />
<font color="#804040">&nbsp;71 </font><font color="#0000ff">&nbsp;&nbsp; * </font><br />
<font color="#804040">&nbsp;72 </font><font color="#0000ff">&nbsp;&nbsp; * </font><font color="#6a5acd">@return</font><font color="#0000ff">&nbsp;The display view for viewing the contents</font><br />
<font color="#804040">&nbsp;73 </font><font color="#0000ff">&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; of the watch list.</font><br />
<font color="#804040">&nbsp;74 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">&nbsp;75 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;View getDisplay()&nbsp;<br />
<font color="#804040">&nbsp;76 </font>&nbsp;&nbsp;{<br />
<font color="#804040">&nbsp;77 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>return</b></font>&nbsp;display;<br />
<font color="#804040">&nbsp;78 </font>&nbsp;&nbsp;}<br />
<font color="#804040">&nbsp;79 </font><br />
<font color="#804040">&nbsp;80 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;81 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Retrieves the last item that was selected, but not</font><br />
<font color="#804040">&nbsp;82 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;necessarily &quot;clicked&quot;.</font><br />
<font color="#804040">&nbsp;83 </font><font color="#0000ff">&nbsp;&nbsp; * </font><br />
<font color="#804040">&nbsp;84 </font><font color="#0000ff">&nbsp;&nbsp; * </font><font color="#6a5acd">@return</font><font color="#0000ff">&nbsp;The item that is currently at the cursor.</font><br />
<font color="#804040">&nbsp;85 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">&nbsp;86 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;T getSelected()&nbsp;<br />
<font color="#804040">&nbsp;87 </font>&nbsp;&nbsp;{<br />
<font color="#804040">&nbsp;88 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>return</b></font>&nbsp;highlighted;<br />
<font color="#804040">&nbsp;89 </font>&nbsp;&nbsp;}<br />
<font color="#804040">&nbsp;90 </font><br />
</font></p>
<p>Next, the data from the list needs to be loaded into the table. This is done by adding a series table rows. Each row needs to be made focusable. Listeners are added to row to handle the highlighting and when the user clicks on a row. For highlighting, the <a href="http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html">OnFocusChangeListener</a> and <a href="http://developer.android.com/reference/android/view/View.OnTouchListener.html">OnTouchListener</a> are required. Clicking is handled by <a href="http://developer.android.com/reference/android/view/View.OnClickListener.html">OnClickListener</a>.<br />
<font face="monospace"><br />
<font color="#804040">&nbsp;91 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">&nbsp;92 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Loads the current contents of the list to the </font><br />
<font color="#804040">&nbsp;93 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;displayed list.</font><font color="#0000ff">&nbsp;</font><br />
<font color="#804040">&nbsp;94 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">&nbsp;95 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;initialiseDisplay()&nbsp;<br />
<font color="#804040">&nbsp;96 </font>&nbsp;&nbsp;{<br />
<font color="#804040">&nbsp;97 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// All rows will have the same parameters, so just </font><br />
<font color="#804040">&nbsp;98 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// create it once.</font><br />
<font color="#804040">&nbsp;99 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;TableRow.LayoutParams rowParams = <font color="#804040"><b>new</b></font>&nbsp;<br />
<font color="#804040">100 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TableRow.LayoutParams(<br />
<font color="#804040">101 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TableRow.LayoutParams.FILL_PARENT,<br />
<font color="#804040">102 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TableRow.LayoutParams.WRAP_CONTENT);<br />
<font color="#804040">103 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">104 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">105 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// Go through the list and create table entries for </font><br />
<font color="#804040">106 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// each one.</font><br />
<font color="#804040">107 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>for</b></font>&nbsp;(T item: itemsCollection)&nbsp;<br />
<font color="#804040">108 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">109 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TableRow newRow = <font color="#804040"><b>new</b></font>&nbsp;TableRow(appContext);<br />
<font color="#804040">110 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.setLayoutParams(rowParams);<br />
<font color="#804040">111 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">112 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;View[]&nbsp;content = dataAdapter.getContent(item);<br />
<font color="#804040">113 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>for</b></font>&nbsp;(<font color="#2e8b57"><b>int</b></font>&nbsp;index = <font color="#ff00ff">0</font>; index &lt; content.length; index++)&nbsp;<br />
<font color="#804040">114 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">115 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.addView(content[index]);<br />
<font color="#804040">116 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">117 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">118 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.setFocusable(<font color="#ff00ff">true</font>);<br />
<font color="#804040">119 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.setFocusableInTouchMode(<font color="#ff00ff">true</font>);<br />
<font color="#804040">120 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.setOnFocusChangeListener(<br />
<font color="#804040">121 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>new</b></font>&nbsp;RowHighlighter(item));<br />
<font color="#804040">122 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newRow.setOnClickListener(<font color="#804040"><b>new</b></font>&nbsp;RowSelector(item));<br />
<font color="#804040">123 </font><br />
<font color="#804040">124 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.addView(newRow);<br />
<font color="#804040">125 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">126 </font>&nbsp;&nbsp;}<br />
<font color="#804040">127 </font>&nbsp;&nbsp;<br />
</font></p>
<p>Notifications about which item the user clicks is sent via the <b>SelectionReceiver</b>. This is an external class that we define. Of course, there needs to be a way of setting which instance of the <b>SelectionReceiver</b> will receive the notification.<br />
<font face="monospace"><br />
<font color="#804040">128 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">129 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Changes the receiver that is notified when an item </font><br />
<font color="#804040">130 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;is &quot;clicked&quot;.</font><br />
<font color="#804040">131 </font><font color="#0000ff">&nbsp;&nbsp; * </font><br />
<font color="#804040">132 </font><font color="#0000ff">&nbsp;&nbsp; * </font><font color="#6a5acd">@param</font><font color="#008080">&nbsp;receiver</font><br />
<font color="#804040">133 </font><font color="#0000ff">&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The receiver that will be notified of changes.</font><br />
<font color="#804040">134 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">135 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;setSelectionReceiver(<br />
<font color="#804040">136 </font>&nbsp;&nbsp; SelectionReceiver&lt;T&gt; receiver)<br />
<font color="#804040">137 </font>&nbsp;&nbsp;{<br />
<font color="#804040">138 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.selectionObserver = receiver;<br />
<font color="#804040">139 </font>&nbsp;&nbsp;}<br />
<font color="#804040">140 </font>&nbsp;&nbsp;<br />
</font></p>
<p>The definition for the highlighting class:<br />
<font face="monospace"><br />
<font color="#804040">141 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">142 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;This focus change listener handles the changing the</font><br />
<font color="#804040">143 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;background colour for highlighting the focused row.</font><br />
<font color="#804040">144 </font><font color="#0000ff">&nbsp;&nbsp; * It also updates the variable keeping track the</font><br />
<font color="#804040">145 </font><font color="#0000ff">&nbsp;&nbsp; * highlighted item.</font><br />
<font color="#804040">146 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">147 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;RowHighlighter <font color="#2e8b57"><b>implements</b></font>&nbsp;<br />
<font color="#804040">148 </font>&nbsp;&nbsp;&nbsp;&nbsp;View.OnFocusChangeListener, View.OnTouchListener<br />
<font color="#804040">149 </font>&nbsp;&nbsp;{<br />
<font color="#804040">150 </font><br />
<font color="#804040">151 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">152 </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;The item that the highlighter is associated with.</font><font color="#0000ff">&nbsp;</font><br />
<font color="#804040">153 </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; */</font><br />
<font color="#804040">154 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;T association;<br />
<font color="#804040">155 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">156 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;RowHighlighter(T association)&nbsp;<br />
<font color="#804040">157 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">158 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.association = association;<br />
<font color="#804040">159 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">160 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">161 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">162 </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;</font><font color="#6a5acd">{@inheritDoc}</font><br />
<font color="#804040">163 </font><font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
<font color="#804040">164 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a020f0">@Override</font><br />
<font color="#804040">165 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;onFocusChange(View v, <font color="#2e8b57"><b>boolean</b></font>&nbsp;hasFocus)<br />
<font color="#804040">166 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">167 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;bgColour = Color.TRANSPARENT;<br />
<font color="#804040">168 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>if</b></font>&nbsp;(hasFocus == <font color="#ff00ff">true</font>)&nbsp;<br />
<font color="#804040">169 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">170 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bgColour = Color.RED;<br />
<font color="#804040">171 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;highlighted = association;<br />
<font color="#804040">172 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">173 </font><br />
<font color="#804040">174 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v.setBackgroundColor(bgColour);<br />
<font color="#804040">175 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">176 </font><br />
<font color="#804040">177 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">178 </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;</font><font color="#6a5acd">{@inheritDoc}</font><br />
<font color="#804040">179 </font><font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
<font color="#804040">180 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a020f0">@Override</font><br />
<font color="#804040">181 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>boolean</b></font>&nbsp;onTouch(View v, MotionEvent event)<br />
<font color="#804040">182 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">183 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>if</b></font>&nbsp;(event.getAction()&nbsp;!= MotionEvent.ACTION_UP)&nbsp;<br />
<font color="#804040">184 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">185 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v.requestFocus();<br />
<font color="#804040">186 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">187 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>return</b></font>&nbsp;<font color="#ff00ff">false</font>;<br />
<font color="#804040">188 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">189 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">190 </font>&nbsp;&nbsp;}<br />
<font color="#804040">191 </font>&nbsp;&nbsp;<br />
</font></p>
<p>Finally, the internal class for updating the row that is selected.<br />
<font face="monospace"><br />
<font color="#804040">192 </font>&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">193 </font><font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Handles the &quot;clicking&quot; on a row.</font><br />
<font color="#804040">194 </font><font color="#0000ff">&nbsp;&nbsp; * </font><br />
<font color="#804040">195 </font><font color="#0000ff">&nbsp;&nbsp; * </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;Kah</font><br />
<font color="#804040">196 </font><font color="#0000ff">&nbsp;&nbsp; */</font><br />
<font color="#804040">197 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;RowSelector <font color="#2e8b57"><b>implements</b></font>&nbsp;View.OnClickListener<br />
<font color="#804040">198 </font>&nbsp;&nbsp;{<br />
<font color="#804040">199 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>private</b></font>&nbsp;<font color="#2e8b57"><b>final</b></font>&nbsp;T association;<br />
<font color="#804040">200 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">201 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;RowSelector(T association)&nbsp;<br />
<font color="#804040">202 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">203 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.association = association;<br />
<font color="#804040">204 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">205 </font>&nbsp;&nbsp;&nbsp;&nbsp;<br />
<font color="#804040">206 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br />
<font color="#804040">207 </font><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;</font><font color="#6a5acd">{@inheritDoc}</font><br />
<font color="#804040">208 </font><font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
<font color="#804040">209 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a020f0">@Override</font><br />
<font color="#804040">210 </font>&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;onClick(View v)<br />
<font color="#804040">211 </font>&nbsp;&nbsp;&nbsp;&nbsp;{<br />
<font color="#804040">212 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#804040"><b>if</b></font>&nbsp;(selectionObserver != <font color="#ff00ff">null</font>)&nbsp;{<br />
<font color="#804040">213 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selectionObserver.itemSelected(association);<br />
<font color="#804040">214 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">215 </font>&nbsp;&nbsp;&nbsp;&nbsp;}<br />
<font color="#804040">216 </font>&nbsp;&nbsp;}<br />
<font color="#804040">217 </font>}<br />
<font color="#804040">218 </font>&nbsp;<br />
<font color="#804040">219 </font><br />
</font></p>
<p>If you wish to download the source code, you can get it from <a href="http://www.box.net/shared/0m25njzkjk">here</a>. As mentioned previously, this seems a long way of achieving a selectable list of items with three columns. Using a <b>ListView</b>, the item selection and item highlighting is taken care of. But how to use <b>ListView</b> is left for another day.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=106&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/03/29/adding-selection-functionality-to-the-table-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Ion, a Tiling Window Manager</title>
		<link>http://kahdev.wordpress.com/2009/02/24/using-ion-a-tiling-window-manager/</link>
		<comments>http://kahdev.wordpress.com/2009/02/24/using-ion-a-tiling-window-manager/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 13:22:17 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ion]]></category>
		<category><![CDATA[Window Manager]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=95</guid>
		<description><![CDATA[When working in Linux, I usually have multiple windows open. I always need at least one terminal to compile and execute commands. I would usually use Vim to edit my files too. Most likely, I would also have Firefox open with some information. During my work cycle, I constantly need to use these three windows.This means I need to be able to see the contents of these windows. The default Gnome and KDE window managers are rather inefficient at this because they can stack windows on top of one another. To make them non-overlapping, I have to individually resize the windows.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=95&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When working in Linux, I usually have multiple windows open. I always need at least one terminal to compile and execute commands. I would usually use Vim to edit my files too. Most likely, I would also have Firefox open with some information. During my work cycle, I constantly need to use these three windows.This means I need to be able to see the contents of these windows. The default Gnome and KDE window managers are rather inefficient at this because they can stack windows on top of one another. To make them non-overlapping, I have to individually resize the windows.</p>
<p>Ion is a tiling window manager. Unlike the stacking window managers, a tiling window manager can arrange your windows, such that they are non-overlapping (note I said can, because some they can still let you put a window on top of another).</p>
<div id="attachment_93" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-93" title="Ion screen shot" src="http://kahdev.files.wordpress.com/2009/02/screenshot.jpg?w=450&#038;h=271" alt="Ion window manager with three non-overlapping frames." width="450" height="271" /><p class="wp-caption-text">Ion window manager with three non-overlapping frames.</p></div>
<p>To install, visit the <a href="http://www.modeemi.fi/~tuomov/ion/">Ion website</a>. If you are using Ubuntu, you can install the Ion3 package instead. Once installed and running, you are likely to be presented with a window containing two frames.</p>
<h3>Starting Applications in Frames</h3>
<p>To open an application in the frame, press <span style="color:#993300;">F3</span> and type in the command to start it (such as &#8220;firefox&#8221;). If you want to open up a terminal, you can press just <span style="color:#993300;">F2</span> instead and <span style="color:#993300;">F1</span> for man page. There are even short cuts to use SSH (F4), edit files (<span style="color:#993300;">F5</span>) and view text files (<span style="color:#993300;">F6</span>).</p>
<p>If you have tried starting multiple applications, you&#8217;ll notice that they will all open up to the frame that is in focus. Moving applications to the other frame can be done using the keyboard. For a number of the keyboard shortcuts, Ion uses the <span style="color:#993300;">mod</span> key. By default, the <span style="color:#993300;">mod</span> key is set to the <span style="color:#993300;">alt</span> key. If you do not like this, you can configure Ion to use a different key.</p>
<h3>Moving Between Windows</h3>
<p>Switching between the windows in the same frame is done by pressing <span style="color:#993300;">mod + k  n</span> (That is, press <span style="color:#993300;">mod</span> and <span style="color:#993300;">k</span> keys simultaneously. Let go of the <span style="color:#993300;">k</span> key, but keep holding the <span style="color:#993300;">mod</span> key. Then press <span style="color:#993300;">n</span> while still holding the mod <span style="color:#993300;">key</span>).</p>
<h3>Moving Windows to Other Frames</h3>
<p>Using a single frame is not a good utilisation of the available screen space.  In Ion, moving an application to another frame requires you to &#8220;tag&#8221; it first.  To tag an application, bring the application to focus and pressing <span style="color:#993300;">mod + t</span>. A mark is placed at the top corner of the title bar to show that it has been tagged.</p>
<div id="attachment_94" class="wp-caption aligncenter" style="width: 107px"><img class="size-full wp-image-94" title="tag-mark" src="http://kahdev.files.wordpress.com/2009/02/tag-mark.jpg?w=97&#038;h=22" alt="A tagged title bar." width="97" height="22" /><p class="wp-caption-text">A title bar with a &quot;tagged&quot; mark in the top right corner.</p></div>
<p>Pressing <span style="color:#993300;">mod + t</span> again will remove the tagging. It is possible to have multiple windows tagged simultaneously. This is particularly helpful when you want to move multiple windows</p>
<h3>Attaching Windows</h3>
<p>Once the window the window is tagged, move horizontally to the adjacent frame with <span style="color:#993300;">mod + tab</span>. To move vertically, use <span style="color:#993300;">mod + n</span> or <span style="color:#993300;">mod + p</span>. Pressing <span style="color:#993300;">mod + a</span> will prompt you for the name of the window to attach to the frame. If you want to place all of the tagged windows to the frame, you can simply use <span style="color:#993300;">mod + k a</span> (like before, press <span style="color:#993300;">mod + k</span> then <span style="color:#993300;">mod + a</span>, without letting go with the <span style="color:#993300;">mod</span> key).</p>
<h3>Reorganising Your Frames</h3>
<p>Ion allows you to reorganise your frames, however you want. First, to resize a frame, press <span style="color:#993300;">mod + r</span> and then use arrow keys to make the frame grow. Windows can be maximised horizontally (<span style="color:#993300;">mod + k h</span>) and vertically (<span style="color:#993300;">mod + k v</span>). To further split the current frame, use <span style="color:#993300;">mod + k s</span> for horizontal splits. To delete the current frame, use <span style="color:#993300;">mod + k x</span>.</p>
<h3>Workspaces</h3>
<p>Finally, Ion support for multiple workspaces (similar to having multiple desktops). Workspaces are created using the <span style="color:#993300;">F9</span> key. Before one is created, it will prompt you for a name for the workspace. If you enter the name of an existing workspace, it will go to that one instead. You can also switch between workspaces by holding the mod key and pressing a numeric key.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=95&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/02/24/using-ion-a-tiling-window-manager/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/02/screenshot.jpg" medium="image">
			<media:title type="html">Ion screen shot</media:title>
		</media:content>

		<media:content url="http://kahdev.files.wordpress.com/2009/02/tag-mark.jpg" medium="image">
			<media:title type="html">tag-mark</media:title>
		</media:content>
	</item>
		<item>
		<title>Verifying Using a Certificate Store</title>
		<link>http://kahdev.wordpress.com/2009/02/15/verifying-using-a-certificate-store/</link>
		<comments>http://kahdev.wordpress.com/2009/02/15/verifying-using-a-certificate-store/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 12:25:02 +0000</pubDate>
		<dc:creator>kahgoh</dc:creator>
				<category><![CDATA[OpenSSL]]></category>

		<guid isPermaLink="false">http://kahdev.wordpress.com/?p=89</guid>
		<description><![CDATA[An certificate store can be used to hold multiple CA certificates. It is used
for verification purposes, when you have multiple CA certificates, but you
do not necessarily know which of those CA certificates signed the
certificate. When verifying the certificate, OpenSSL will look for the CA
certificate or the chain in the store.
Setting up the store programatically involves [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=89&subd=kahdev&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>An certificate store can be used to hold multiple CA certificates. It is used<br />
for verification purposes, when you have multiple CA certificates, but you<br />
do not necessarily know which of those CA certificates signed the<br />
certificate. When verifying the certificate, OpenSSL will look for the CA<br />
certificate or the chain in the store.</p>
<p>Setting up the store programatically involves allocating memory for the<br />
store via <b>X509_STORE_new</b> and then loading certificates into it. There<br />
are two ways of placing the certificates into the store &#8211; by loading and<br />
adding each individual certificate or supplying the location of CA<br />
certificates. For this tutorial, we&#8217;ll load each certificate programatically.<br />
<font face="monospace"><br />
<font color="#a52a2a">&nbsp;1 </font><font color="#2e8b57"><b>void</b></font>&nbsp;verifyCertificate()<br />
<font color="#a52a2a">&nbsp;2 </font>{<br />
<font color="#a52a2a">&nbsp;3 </font>&nbsp;&nbsp;X509 *cert = loadCert(<font color="#ff00ff">&quot;cert.pem&quot;</font>);<br />
<font color="#a52a2a">&nbsp;4 </font>&nbsp;&nbsp;X509_STORE *store = X509_STORE_new();<br />
<font color="#a52a2a">&nbsp;5 </font><br />
<font color="#a52a2a">&nbsp;6 </font>&nbsp;&nbsp;loadToStore(<font color="#ff00ff">&quot;cert-1.pem&quot;</font>, store);<br />
<font color="#a52a2a">&nbsp;7 </font>&nbsp;&nbsp;loadToStore(<font color="#ff00ff">&quot;cert-2.pem&quot;</font>, store);<br />
<font color="#a52a2a">&nbsp;8 </font>&nbsp;&nbsp;loadToStore(<font color="#ff00ff">&quot;cert-3.pem&quot;</font>, store);<br />
<font color="#a52a2a">&nbsp;9 </font><br />
</font><br />
The listing for loading the certificate into the store will be shown later.<br />
Verification is performed using a store context. Setting up a context<br />
involves allocating space for a store context and initialising it.<br />
<font face="monospace"><br />
<font color="#a52a2a">10 </font>&nbsp;&nbsp;<font color="#0000ff">// Create the context to verify the certificate. </font><br />
<font color="#a52a2a">11 </font>&nbsp;&nbsp;X509_STORE_CTX *ctx = X509_STORE_CTX_new();<br />
<font color="#a52a2a">12 </font><br />
<font color="#a52a2a">13 </font>&nbsp;&nbsp;<font color="#0000ff">// Initial the store to verify the certificate.</font><br />
<font color="#a52a2a">14 </font>&nbsp;&nbsp;X509_STORE_CTX_init(ctx, store, cert, <font color="#ff00ff">NULL</font>);<br />
<font color="#a52a2a">15 </font><br />
<font color="#a52a2a">16 </font>&nbsp;&nbsp;X509_verify_cert(ctx);<br />
<font color="#a52a2a">17 </font><br />
<font color="#a52a2a">18 </font>&nbsp;&nbsp;X509_STORE_CTX_cleanup(ctx);<br />
<font color="#a52a2a">19 </font>&nbsp;&nbsp;X509_STORE_CTX_free(ctx);<br />
<font color="#a52a2a">20 </font>&nbsp;&nbsp;X509_STORE_free(store);<br />
<font color="#a52a2a">21 </font>&nbsp;&nbsp;ctx = <font color="#ff00ff">NULL</font>;<br />
<font color="#a52a2a">22 </font>&nbsp;&nbsp;store = <font color="#ff00ff">NULL</font>;<br />
<font color="#a52a2a">23 </font>}<br />
<font color="#a52a2a">24 </font><br />
</font><br />
The third parameter to <b>X509_STORE_CTX_init</b>, <b>cert</b>, is the<br />
certificate that is going to be verified. The call to <b>X509_verify_cert</b><br />
should also return the value one, if verification succeeds. </p>
<p>Adding a certificate to the store requires the certificate to be read first.<br />
<font face="monospace"><br />
<font color="#a52a2a">25 </font><font color="#2e8b57"><b>void</b></font>&nbsp;loadToStore(std::string file, X509_STORE *&amp;store)<br />
<font color="#a52a2a">26 </font>{<br />
<font color="#a52a2a">27 </font>&nbsp;&nbsp;X509 *cert = loadCert(file);<br />
<font color="#a52a2a">28 </font>&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(cert != <font color="#ff00ff">NULL</font>)<br />
<font color="#a52a2a">29 </font>&nbsp;&nbsp;{<br />
<font color="#a52a2a">30 </font>&nbsp;&nbsp;&nbsp;&nbsp;X509_STORE_add_cert(store, cert);<br />
<font color="#a52a2a">31 </font>&nbsp;&nbsp;}<br />
<font color="#a52a2a">32 </font>&nbsp;&nbsp;<font color="#a52a2a"><b>else</b></font><br />
<font color="#a52a2a">33 </font>&nbsp;&nbsp;{<br />
<font color="#a52a2a">34 </font>&nbsp;&nbsp;&nbsp;&nbsp;std::cout &lt;&lt; <font color="#ff00ff">&quot;Can not load certificate &quot;</font>&nbsp;<br />
<font color="#a52a2a">35 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt; file &lt;&lt; std::endl;<br />
<font color="#a52a2a">36 </font>&nbsp;&nbsp;}<br />
<font color="#a52a2a">37 </font>}<br />
<font color="#a52a2a">38 </font><br />
<font color="#a52a2a">39 </font>X509 *loadCert(std::string file)<br />
<font color="#a52a2a">40 </font>{<br />
<font color="#a52a2a">41 </font>&nbsp;&nbsp;<font color="#2e8b57"><b>FILE</b></font>&nbsp;*fp = fopen(file.c_str(), <font color="#ff00ff">&quot;r&quot;</font>);<br />
<font color="#a52a2a">42 </font>&nbsp;&nbsp;X509 *cert = PEM_read_X509(fp, <font color="#ff00ff">NULL</font>, <font color="#ff00ff">NULL</font>, <font color="#ff00ff">NULL</font>);<br />
<font color="#a52a2a">43 </font>&nbsp;&nbsp;fclose(fp);<br />
<font color="#a52a2a">44 </font>&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;cert;<br />
<font color="#a52a2a">45 </font>}<br />
</font><br />
The process of adding the certificate should be self-explanatory from the listing.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kahdev.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kahdev.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kahdev.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kahdev.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kahdev.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kahdev.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kahdev.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kahdev.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kahdev.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kahdev.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kahdev.wordpress.com&blog=4034716&post=89&subd=kahdev&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kahdev.wordpress.com/2009/02/15/verifying-using-a-certificate-store/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">kahgoh</media:title>
		</media:content>
	</item>
	</channel>
</rss>