<?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>Luminis Software Development &#187; toolkit</title>
	<atom:link href="http://lsd.luminis.nl/en/tag/toolkit/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.nl</link>
	<description></description>
	<lastBuildDate>Wed, 18 Aug 2010 10:10:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using GWT to create an OSGi-aware web application</title>
		<link>http://lsd.luminis.nl/en/using-gwt-to-create-an-osgi-aware-web-application/</link>
		<comments>http://lsd.luminis.nl/en/using-gwt-to-create-an-osgi-aware-web-application/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 20:14:29 +0000</pubDate>
		<dc:creator>Angelo van der Sijpt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache ACE]]></category>
		<category><![CDATA[Apache Felix]]></category>
		<category><![CDATA[extender]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[OSGi]]></category>
		<category><![CDATA[pax]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[smartservices]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://lsd.luminis.net/?p=217</guid>
		<description><![CDATA[<p><a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> is cool, and so is OSGi. However, creating a web application that can use OSGi services is not that easy. By the end of this tutorial, you will have created a GWT project that delivers a usable jar. If you're impatient, skip to the end for the downloadable Eclipse project.</p>]]></description>
			<content:encoded><![CDATA[<p><strong>Update 2010-02-20</strong> <em>Both Pax Runner 1.3.0 and GWT 2.0 have caused quite some changes to this post. I have tried to stay up to date as well as I could (the zipped project now uses GWT 2.0), but you might find some inconsistencies when following the tutorial.</em></p>
<p><a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> is cool, and so is OSGi. However, when building a web UI for <a href="http://cwiki.apache.org/confluence/display/ACE/Index">Apache ACE</a>, I found out that creating a web application that can use OSGi services is not that easy. By the end of this tutorial, you will have created a GWT project that delivers a usable jar. If you&#8217;re impatient, skip to the end for the downloadable Eclipse project.</p>
<h3>Step 1: Create a GWT project</h3>
<p>Create a regular GWT project using the regular webAppCreator; this will give you a project that includes an <a href="http://ant.apache.org">Ant</a> buildfile, we will need that later on.</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">angelos:workspace angelos$ ./gwt-mac-1.6.4/webAppCreator -out GwtDemo net.luminis.gwt.gwtdemo
Created directory GwtDemo/src
Created directory GwtDemo/war
Created directory GwtDemo/war/WEB-INF
Created directory GwtDemo/war/WEB-INF/lib
Created directory GwtDemo/src/net/luminis/gwt
Created directory GwtDemo/src/net/luminis/gwt/client
Created directory GwtDemo/src/net/luminis/gwt/server
Created file GwtDemo/src/net/luminis/gwt/gwtdemo.gwt.xml
Created file GwtDemo/war/gwtdemo.html
Created file GwtDemo/war/gwtdemo.css
Created file GwtDemo/war/WEB-INF/web.xml
Created file GwtDemo/src/net/luminis/gwt/client/gwtdemo.java
Created file GwtDemo/src/net/luminis/gwt/client/GreetingService.java
Created file GwtDemo/src/net/luminis/gwt/client/GreetingServiceAsync.java
Created file GwtDemo/src/net/luminis/gwt/server/GreetingServiceImpl.java
Created file GwtDemo/build.xml
Created file GwtDemo/README.txt
Created file GwtDemo/.project
Created file GwtDemo/.classpath
Created file GwtDemo/gwtdemo.launch
Created file GwtDemo/war/WEB-INF/lib/gwt-servlet.jar</pre></div></div>

<p>If you want to, you can import this project directly into your Eclipse. If you check the mark &#8220;use Google Web Toolkit&#8221; in the project properties, you can use all the same goodies that creating the project in Eclipse would have given you. Remember to replace the buildpath entries for gwt-user.jar and gwt-dev-*.jar by a Library import for GWT.</p>
<h3>Step 2: Include the necessary OSGi references</h3>
<p>Create an &#8216;ext&#8217; directory, and add org.osgi.core.jar to that. In Eclipse, add this jar to your build path.</p>
<h3>Step 3: Use OSGi services from your web applicaiton</h3>
<p>We will first add a simple Activator on the server side.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.luminis.gwt.server</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.framework.BundleActivator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.osgi.framework.BundleContext</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Activator</span> <span style="color: #000000; font-weight: bold;">implements</span> BundleActivator <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> BundleContext m_context<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> BundleContext getContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> m_context<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> start<span style="color: #009900;">&#40;</span>BundleContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        m_context <span style="color: #339933;">=</span> context<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> stop<span style="color: #009900;">&#40;</span>BundleContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, we up the GreetingServiceImpl to actually use this <a href="http://www.osgi.org/javadoc/r4v41/org/osgi/framework/BundleContext.html">BundleContext</a> (note that we use it directly here, but you could use it to get other services, create a <a href="http://www.osgi.org/javadoc/r4v41/org/osgi/util/tracker/ServiceTracker.html">ServiceTracker</a>, etc.)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> greetServer<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> serverInfo <span style="color: #339933;">=</span> getServletContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServerInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span> userAgent <span style="color: #339933;">=</span> getThreadLocalRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;User-Agent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Hello, &quot;</span> <span style="color: #339933;">+</span> input <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;!
&nbsp;
I am running &quot;</span> <span style="color: #339933;">+</span> serverInfo
    <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;.
&nbsp;
It looks like you are using:&quot;</span> <span style="color: #339933;">+</span> userAgent <span style="color: #339933;">+</span>
    <span style="color: #0000ff;">&quot;The framework we run from has &quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Activator</span>.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBundles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; bundles in it.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Step 4: Add OSGi dependencies for the compiler</h3>
<p>Add our OSGi dependencies to the classpath, so the compiler can find all of it.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #808080; font-style: italic;">&lt;!-- Add any additional non-server libs (such as JUnit) --&gt;</span></pre></div></div>

<p>Right, let&#8217;s give it a try!</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">angelos:GwtDemo angelos$ ant war
Buildfile: build.xml
&nbsp;
...some output removed...
&nbsp;
war:
[zip] Building zip: /Users/angelos/workspace/workspace/GwtDemo/gwtdemo.war
&nbsp;
BUILD SUCCESSFUL
Total time: 36 seconds</pre></div></div>

<p>You will find a war in your project directory now. There still is one ingredient we need. We need to make this into a proper bundle. We can use <a href="http://www.aqute.biz/Code/Bnd">bnd</a> to help us with that.</p>
<h3>Step 5: use bnd to create a proper war</h3>
<p>Download bnd, and put into a lib directory, and add it to your buildfile.</p>
<p>We create a new target that transforms our war into a jar.</p>

<div class="wp_syntax"><div class="code"><pre class="ant" style="font-family:monospace;">&lt;target name=&quot;jar&quot;&gt;
    &lt;copy file=&quot;gwtdemo.war&quot; tofile=&quot;gwtdemo.jar&quot;/&gt;
    &lt;echo file=&quot;gwtdemo.bnd&quot;&gt;Import-Package: junit.framework;resolution:=optional, com.google.gwt.*;resolution:=optional, org.w3c.*;resolution:=optional, sun.misc;resolution:=optional, javax.imageio;resolution:=optional, javax.servlet.*;resolution:=optional, *
Bundle-Name: GWT Demo
Bundle-ClassPath: WEB-INF/classes, WEB-INF/lib/gwt-servlet.jar
Bundle-SymbolicName: net.luminis.gwt.gwtdemo
Webapp-Context: gwtdemo
Bundle-Activator: net.luminis.gwt.server.Activator
    &lt;/echo&gt;
    &lt;bndwrap jars=&quot;gwtdemo.jar&quot; output=&quot;gwtdemo.jar&quot;/&gt;
    &lt;jar file=&quot;gwtdemo.jar&quot; update=&quot;true&quot;&gt;
    &lt;manifest&gt;
        &lt;attribute name=&quot;Bundle-ClassPath&quot; value=&quot;WEB-INF/classes, WEB-INF/lib/gwt-servlet.jar, .&quot;/&gt;
     &lt;/manifest&gt;
    &lt;/jar&gt;
    &lt;delete file=&quot;gwtdemo.bnd&quot;/&gt;
&lt;/target&gt;</pre></div></div>

<p>What&#8217;s happening here?</p>
<ul>
<li>we copy our war to the same file, but with a jar extension,</li>
<li>we create a file for bnd to use, stating that we
<ul>
<li>want optional imports for junit and the gwt benchmarks, and non-optional imports for everything else (that what the * is for),</li>
<li>have some classes that we want bnd to scan for finding dependencies,</li>
<li>want to use a given Webapp-Context (this is a <a href="http://paxrunner.ops4j.org/display/paxweb/WAR+Extender">Pax war extender</a> specific entry),</li>
</ul>
</li>
<li>let bnd do its magic,</li>
<li>update our manifest: we put the . back on the classpath. This is important for the web application to find all resources, but if we would tell bnd to do it like this, it would treat . as the root of the classpath.</li>
<li>Finally, we delete that temporary bnd file.</li>
</ul>
<p>What does that give us?</p>

<div class="wp_syntax"><div class="code"><pre class="language" style="font-family:monospace;">angelos:GwtDemo angelos$ ant jar
Buildfile: build.xml
&nbsp;
...some output removed...
&nbsp;
jar:
[copy] Copying 1 file to /Users/angelos/workspace/workspace/GwtDemo
[bndwrap] gwtdemo 41 910305
[bndwrap] Warnings
[bndwrap] Superfluous export-package instructions: [WEB-INF.classes.net, gwtdemo.gwt.standard.images, WEB-INF, gwtdemo, WEB-INF.classes.net.luminis.gwt, gwtdemo.gwt.standard, WEB-INF.classes.net.luminis, WEB-INF.lib, WEB-INF.classes, gwtdemo.gwt.standard.images.ie6, WEB-INF.classes.net.luminis.gwt.client, WEB-INF.classes.net.luminis.gwt.server, gwtdemo.gwt]
[jar] Updating jar: /Users/angelos/workspace/workspace/GwtDemo/gwtdemo.jar
[delete] Deleting: /Users/angelos/workspace/workspace/GwtDemo/gwtdemo.bnd
&nbsp;
BUILD SUCCESSFUL
Total time: 23 seconds</pre></div></div>

<p>That&#8217;s it! You can now deploy this jar into a framework that uses the pax web tools. Right, let&#8217;s give that a try.</p>
<p>Download <a href="http://paxrunner.ops4j.org/space/Pax+Runner">pax-runner</a>, and unzip that somewhere. Copy in your new jar, an try the following command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">angelos:pax-runner angelos$ <span style="color: #c20cb9; font-weight: bold;">sh</span> bin<span style="color: #000000; font-weight: bold;">/</span>pax-run.sh <span style="color: #660033;">--profiles</span>=war,compendium gwtdemo.jar</pre></div></div>

<p>Now visit <a href="http://localhost:8080/gwtdemo">http://localhost:8080/gwtdemo</a>:</p>
<p><img class="alignnone size-full wp-image-450" title="gwtdemo" src="http://lsd.luminis.nl/wp-content/uploads/2009/07/gwtdemo.png" alt="gwtdemo" width="500" height="432" /></p>
<h3>Summary</h3>
<p>So, what did we need?</p>
<ul>
<li>A fairly regular GWT project, create with an Ant file,</li>
<li>some code that tries to use OSGi services,</li>
<li>some bnd magic to make the war into a jar,</li>
<li>Pax tools to get it all running quickly.</li>
</ul>
<p>If you don&#8217;t want to use pax runner, you can need to deploy <a href="http://paxrunner.ops4j.org/display/paxweb/WAR+Extender">pax-web-extender-war</a>(<a href="http://repository.ops4j.org/mvn-snapshots/org/ops4j/pax/web/pax-web-extender-war/0.7.0-SNAPSHOT/pax-web-extender-war-0.7.0-20090623.160836-13.jar">jar</a>, snapshot 23 June) and an http server, preferably <a href="http://paxrunner.ops4j.org/display/paxweb/Pax+Web">pax-web-service</a>(<a href="http://repository.ops4j.org/maven2/org/ops4j/pax/web/pax-web-service/0.6.0/pax-web-service-0.6.0.jar">jar</a>), into your framework.</p>
<p>You can download the <a href='http://lsd.luminis.nl/wp-content/uploads/2009/07/gwtdemo.zip'>gwtdemo</a> Eclipse project to play around with it. I have not provided the GWT runtime in this download; you should edit line 4 of the build.xml to point to your installation of GWT.</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/en/using-gwt-to-create-an-osgi-aware-web-application/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>LWUIT &#8211; een lichtgewicht ui toolkit voor Java ME</title>
		<link>http://lsd.luminis.nl/en/lwuit-een-lichtgewicht-ui-toolkit-voor-java-me/</link>
		<comments>http://lsd.luminis.nl/en/lwuit-een-lichtgewicht-ui-toolkit-voor-java-me/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 14:03:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lwuit]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[mobility]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://lsd.luminis.net/?p=194</guid>
		<description><![CDATA[Beschrijving van het opzetten van de ontwikkelomgeving en daarna een simpele LWUIT applicatie ontwikkelen inclusief wat achtergrondinformatie over elk van de stappen.]]></description>
			<content:encoded><![CDATA[<h3>Introductie</h3>
<p>Ooit al eens een Java ME applicatie ontwikkeld voor een specifiek type mobiele telefoon? Wanneer het aankomt op het ontwikkelen van een gelikte interface loop je er al snel tegen aan dat de MIDP implementatie van de telefoon van invloed is op hoe de widgets van de applicatie getoond worden. Nadeel daarvan is dat de UI er op een ander type mobiel nogal anders uit kan zien. Om die reden was men voorheen nog wel eens geneigd om wat dieper in de code te duiken en de wat specifiekere (geliktere) widgets op de (javax.microedition.lcdui.)Canvas uit te werken. Deze Canvas ondersteunt sinds MIDP-2.0 een fullscreen modus: het is mogelijk om de complete applicatie direct op Canvas te ontwikkelen. Hiervan maakt <a href="https://lwuit.dev.java.net/">LWUIT</a> gebruik.</p>
<p>
Mogelijk, maar wel bijzonder tijds-intensief, tenzij je gebruik maakt van het werk van anderen die al wat voorwerk hebben verricht op dit gebied. Een mooi voorbeeld hiervan is &#8220;LWUIT&#8221;, een door Sun ontwikkelde open-source UI toolkit. In tegenstelling tot het ontwerpen van UI&#8217;s met standaard Java ME is het met LWUIT mogelijk om op een Swing-achtige manier user interfaces te maken: layout managers, maar ook de pluggable look &amp; feel, het MVC concept en &#8220;lightweight componenten&#8221; (componenten maken geen gebruik van de native UI controls, maar verzorgen zelf hun rendering en event handling) zijn terug te vinden.</p>
<h3>Setup simpele MIDlet</h3>
<p>Een MIDlet maken waarin met LWUIT een paar knoppen wordt getoond is simpel voor elkaar te krijgen via de volgende stappen:</p>
<li><a href="http://www.netbeans.org/downloads/">Download</a> NetBeans (kies een versie met &#8216;Java ME&#8217; support) en installeer het pakket.</li>
<li><a href="https://lwuit.dev.java.net">Download</a> en unzip de LWUIT zip file (via de &#8216;Download page&#8217; tab &#8211; de zip bevat ook de resource editor).</li>
<li><a href="http://developer.sprint.com">Download</a> en installeer de Sprint wireless toolkit (via de &#8216;Develop&#8217; tab, de &#8216;Technologies&#8217; link en dan de &#8216;Java ME&#8217; link) of een andere toolkit, zoals die van Sun.</li>
<p><p>
Binnen NetBeans is het handig om de LWUIT jar toe te voegen als library via &#8216;Tools&#8217;, &#8216;Libraries en dan de &#8216;New Library&#8230;&#8217; knop. Geef naam, type = &#8216;Class Libraries&#8217;, dan: &#8216;OK&#8217; en &#8216;Add JAR/Folder&#8230;&#8217;: en selecteer het bestand &#8220;LWUIT.jar&#8221; dat te vinden is in de &#8216;lib&#8217; dir van de LWUIT installatie (unzippen van de zip file). Het &#8216;LWUIT_stripped.jar&#8217; bestand is de LWUIT library zonder code die gebruik maakt van JSR 184 (M3G: Mobile 3D Graphics), JSR 75 (PIM: Personal Information Management, FC: File Connection) of JSR 226 (SVG: Scalable 2D Vector Graphics).</p>
<p>
Start vervolgens een nieuw project, kies als categorie &#8216;Java ME&#8217; en als project &#8216;Mobile Application&#8217; en druk op &#8216;Next&#8217;. Het is niet nodig om NetBeans een default MIDlet aan te laten maken; het vinkje bij &#8216;Create Hello MIDlet&#8217; mag weg. Druk weer op &#8216;Next&#8217;. Selecteer de WTK die je hebt geïnstalleerd als &#8216;Emulator Platform&#8217;. LWUIT vereist minimaal MIDP-2.0 bovenop CLDC-1.1, dus i.p.v. MIDP-2.1 die default geselecteerd is zou je MIDP-2.0 kunnen kiezen, maar dit hoeft niet. Druk op &#8216;Finish&#8217;. Maak nu een nieuwe MIDlet aan met de naam &#8216;MyMIDlet&#8217; en kopieer de volgende code er naartoe:</p>
<pre>
import com.sun.lwuit.*;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import javax.microedition.midlet.MIDlet;

public class MyMIDlet extends MIDlet {

    Form form1;

    public void startApp() {
        Display.init(this);
        form1 = new Form("LWUIT Demo Form");
        form1.addCommand(new Command("Quit") {
            public void actionPerformed(ActionEvent ae) {
                destroyApp(true);
                notifyDestroyed();
            }
        });

        form1.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        Button l = new Button("Left");
        l.setAlignment(Label.LEFT);
        Button r = new Button("Right");
        r.setAlignment(Label.RIGHT);
        Button m = new Button("Middle");
        m.setAlignment(Label.CENTER);
        form1.addComponent(l);
        form1.addComponent(r);
        form1.addComponent(m);

        form1.show();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}
</pre>
<p>Omdat het project de LWUIT jar nog niet kent zal je een aantal foutmeldingen zien: via de project properties kan je onder de &#8216;Build&#8217; categorie &#8216;Libraries &amp; Resources&#8217; kiezen. Voeg de LWUIT library die je eerder hebt aangemaakt toe. Omdat er slechts 1 MIDlet in het project zit zal deze MIDlet automatisch gestart worden wanneer je het project <i>right-clickt</i> en dan &#8216;Run&#8217; selecteert. Het resultaat hiervan is een simpele LWUIT applicatie met een paar knopjes!</p>
<h3>MVC</h3>
<p>Een aardige illustratie van het MVC concept bij LWUIT is de List. Voeg het volgende stuk code in voor de &#8216;form1.show()&#8217; uit het vorige voorbeeld.</p>
<pre>
String[] bands = new String[]{
    "AC/DShe",
    "Public Enema",
    "Beverly Beerbellies",
    "Shirley Temple Pilots",
    "Wynona Riders"};
List list = new List(bands);
form1.addComponent(list);
</pre>
<p><img src="http://blog.luminis.nl/luminis/resource/jaapv/lwuit - simpele list.png" title="LWUIT Buttons en List" />.</p>
<p>
Resultaat</p>
<li>Het Model is verantwoordelijk voor de data; zaken als hoeveel items er zijn, maar ook bijvoorbeeld welk item welke offset heeft. Wanneer er veranderingen in het model optreden geeft het model een seintje richting alle (geregistreerde) SelectionListener en DataChangedListener implementaties. De List in dit voorbeeld krijgt een array van Strings aangeleverd en maakt onder water gebruik van een default implementatie van de ListModel interface, het DefaultListModel.</li>
<li>De View wordt in dit geval grotendeels geregeld door een default implementatie van de ListCellRenderer (LCR), de DefaultListCellRenderer. De View is verantwoordelijk voor het tonen van de data die het Model levert. De LCR rendert het object dat vanuit het Model wordt geleverd naar een com.sun.lwuit.Component object dat vervolgens door de List wordt gebruikt om zichzelf te renderen. De default implementatie (is-a com.sun.lwuit.Label) doet simpelweg een <i>toString()</i> van het aangeleverde object, zet dit als text op zichzelf en geeft <i>this</i> terug.</li>
<li>Tot slot is de List zelf de Controller (en eigenlijk ook een beetje van de View &#8211; maakt zwaar gebruik van de LCR, maar rendert uiteindelijk toch zichzelf) die user input afhandelt. Wanneer bijvoorbeeld een ander element in de lijst wordt geselecteerd, dan geeft de List dit door aan het model (die vervolgens weer de geregistreerde SelectionListener objecten triggert).</li>
<p>
Zelf de implementatie van ListModel en ListCellRenderer verzorgen heeft als extra voordeel dat je de reeds bestaande data types direct kan gebruiken en er geen sprake hoeft te zijn van &#8220;state copying&#8221;: er is geen voorbepaald data type wat in de List past.</p>
<p>
Ook goed om te weten is dat de List z&#8217;n Model alleen maar vraagt naar de data-elementen die op het scherm zichtbaar zijn. Dit (performance) aspect wordt belangrijker naarmate de hoeveelheid data groeit of bijv. vanaf een remote locatie moet worden binnengehaald.</p>
<h3>Conclusie</h3>
<p>
Via de bovenstaande stappen is het relatief makkelijk om snel een simpele LWUIT applicatie te maken. Met name voor de ontwikkelaars die hun app op meerdere typen mobiele telefoons willen draaien zal het een aangename verrassing zijn om te zien dat deze voorbeeld-applicatie op alle mobieltjes (die MIDP-2.0/CLDC-1.1 supporten) in uiterlijk en gedrag hetzelfde zal zijn. In een volgende blog zal ik wat verder ingaan op &#8220;fancier features&#8221; zoals Transitions en Theming; het oog wil immers ook wat!</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.nl/en/lwuit-een-lichtgewicht-ui-toolkit-voor-java-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
