<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>House of Metnetsky &#187; swing</title>
	<atom:link href="http://cowarthill.com/blog/index.php/tag/swing/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowarthill.com/blog</link>
	<description>Run Tortoise Run</description>
	<lastBuildDate>Fri, 26 Feb 2010 17:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Filtering File Selectors</title>
		<link>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 17:54:27 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=16</guid>
		<description><![CDATA[Why is it that almost every language/framework offers totally different, and yet similar, solutions for filtering in/out files from selection menus? .NET In the example there are two types of selectors: text files (.txt); all files (*.*). Labels (Text files) are separated from their filter values (*.txt) by the pipe character and each filter type [...]]]></description>
			<content:encoded><![CDATA[<p>Why is it that almost every language/framework offers totally different, and yet similar, solutions for filtering in/out files from selection menus?</p>
<hr />
<h3>.NET</h3>
<pre class="brush: csharp; title: ; notranslate">OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = &quot;Text files (*.txt)|*.txt|All files (*.*)|*.*&quot;</pre>
<p>In the example there are two types of selectors: text files (.txt); all files (*.*). Labels (Text files) are separated from their filter values (*.txt) by the pipe character and each filter type is separated by&#8230; a pipe too! It looks weird, but considering it&#8217;s based off old-school Windows API I can understand and sort of respect their desire to not change. MFC sucks and using weird DSLs instead of creating more objects can have it&#8217;s <em>benefits</em>.</p>
<hr />
<h3>Flash</h3>
<pre class="brush: jscript; title: ; notranslate">var filters:Array = new Array();
filters.push(new FileFilter('Text Files', '*.txt'));
filters.push(new FileFilter('Rich Text', '*.rtf'));

var file:flash.net.FileReference = new FileReference();
file.browse(filters);</pre>
<p>FileFilter is constructed with the rules like so: FileFilter(&#8216;Text Files&#8217;, &#8216;*.txt&#8217;). You can either specify multiple FileFilters or append multiple rulsets to the same label like so: FileFilter(&#8216;Text files&#8217;, &#8216;*.txt;*.txt2&#8242;). Truly a cleaner interface than .NET&#8217;s, but many could argue it&#8217;s Object over kill (AWT/SWING is probably worse).</p>
<hr />
<h3>Gtk+</h3>
<pre class="brush: cpp; title: ; notranslate">GtkFileFilter *file_filter = gtk_file_filter_new();
gtk_file_filter_set_name(file_filter, &quot;Log Files (*.bab)&quot;);
gtk_file_filter_add_pattern(file_filter, &quot;*.bab&quot;);</pre>
<p>Even though Gtk+ is in C, it has a nice interface (which many languages like Flash could be accused of robbing). The name is different than the pattern, and there aren&#8217;t ugly crazy separators like in .NET/MFC.</p>
<hr />
<h3>Swing</h3>
<pre class="brush: java; title: ; notranslate">ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension(&quot;jpg&quot;);
filter.addExtension(&quot;gif&quot;);
filter.setDescription(&quot;JPG &amp;amp;amp;amp; GIF Images&quot;);

JFileChooser dialog = new JFileChooser();
dialog.setFileFilter(filter);</pre>
<p>This isn&#8217;t too bad until you realize that <a title="ExampleFileFilter" href="http://kickjava.com/src/demo/swingset/ExampleFileFilter.java.htm" target="_blank">ExampleFileFilter</a> is a custom class which extends abstract <a title="FileFilter" href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/filechooser/FileFilter.html" target="_blank">FileFilter</a>. Yes there are other ways, but boy is this annoying!</p>
<hr />
<h3>Python (Gtk+)</h3>
<pre class="brush: python; title: ; notranslate">
        dialog = gtk.FileChooserDialog(title=&quot;Select the World&quot;
                            , action=gtk.FILE_CHOOSER_ACTION_OPEN
                            , buttons=(gtk.STOCK_CANCEL
                                                    , gtk.RESPONSE_CANCEL
                                                    , gtk.STOCK_OPEN
                                                    , gtk.RESPONSE_OK))
        filter = gtk.FileFilter()
        filter.set_name(&quot;All files&quot;)
        filter.add_pattern(&quot;*&quot;)
        dialog.add_filter(filter)
</pre>
<p>Just like Gtk+ but with the Python-esk feel.</p>
<hr />
<h3>Conclusion</h3>
<p>I must be stating the obvious: Framework developers hate programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/01/17/filtering-file-selectors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

