Saturday, 20 December 2008

Interactive Digital TV Applications

During last few months I've been playing around interactive applications for digital TV. I think this is a bit unexplored area and there are lots of possibilities to explore. I intend to post about it more often but, for now, I will give you a first taste.

JavaTV is an API to build interactive applications for Digital TV. It is relatively well documented and, well, it is Java, so it is part of a well known and reliable platform. A software for Digital TV runs on a set top box, which is a hardware with a smaller set of resources than regular desktops, but still powerful. A TV application is a kind of JavaME application, and is called, and is called Xlet. It is, in a very simplistic view, an interface you have to implement to have a JavaTV application.

You can use any IDE you like to develop JavaTV applications, but I don't know anyone which has real support for that (like JavaME support, or web development support). This is not a problem, since you will see it is very simple to work with this API. You will need to download Xletview, that is a tool that emulates a TV. You can include xletview.jar in you application, so you will be able to use some of libraries it comes with.

I am going to show you a very simple xlet that comes from InteractiveTvWeb. I liked it because it is very didactic. As you will see, it does actually....nothing. But it does compile and it shows you how any xlet should looks like. Don't be disappointed, because I will post more sophisticated xlets in the next posts. For now, just believe me this is a nice and powerful API and you will have fun with it.

P.S.: If you wanna more fun now, I sugest you to make this code implement a KeyListener, write a System.out.println() to show you something about the key you pressed, compile it, put it into a jar and open it in Xletview. It works just like any Java application.


package javatv;

/**
* The simplest Xlet that you will ever write. This Xlet
* does absolutely nothing, not even print a message.
* However, it is a complete skeleton Xlet that will
* compile, even if it does nothing useful once it's been
* compiled.
*
* This Xlet implements the Javax.tv.xlet.Xlet interface,
* in order to be the main class for an Xlet. All methods
* are inherited from javax.tv.xlet.Xlet
*/
public class MyFirstExampleXlet
implements javax.tv.xlet.Xlet {

/**
* Every Xlet should have a default constructor that
* takes no arguments. No other constructor will get
* called.
*/
public MyFirstExampleXlet() {
// The constructor should contain nothing. Any
// initialisation should be done in the initXlet()
// method, or in the startXlet method if it's time-
// or resource-intensive. That way, the MHP
// middleware can control when the initialisation
// happens in a much more predictable way
}

/**
* Initialise the Xlet. The context for this Xlet
* will get passed in to this method, and a reference
* to it should be stored in case it's needed later.
*
* This is the place where any initialisation should
* be done, unless it takes a lot of time or resources.
* If something goes wrong, then an
* XletStateChangeException should get thrown to let
* the runtime system know that the Xlet can't be
* initialised.
*/
public void initXlet(javax.tv.xlet.XletContext context)
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}

/**
* Start the Xlet. At this point the Xlet can display
* itself on the screen and start interacting with the
* user, or do any resource-intensive tasks. These
* kinds of function should be kept in startXlet(),
* and should *not* be done in initXlet().
*
* As with initXlet(), if there is any problem this
* method should throw an XletStateChangeException to
* tell the runtime system that it can't start.
*
* One of the common pitfalls is that the startXlet()
* method must return to its caller. This means that
* the main functions of the Xlet should be done in
* another thread. The startXlet() method should
* really just create that thread and start it, then
* return.
*/
public void startXlet()
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}

/**
* Pause the Xlet. Unfortunately, it's not clear to
* anyone (including the folks who wrote the MHP
* specification) what this means. Generally, it means
* that the Xlet should free any scarce resources that
* it's using, stop any unnecessary threads, and remove
* itself from the screen.
*
* Unlike the other methods, pauseXlet() can't throw an
* exception to indicate a problem with changing state.
* When the Xlet is told to pause itself, it must do so.
*/
public void pauseXlet() {
// Do nothing for now
}

/**
* Stop the Xlet. The boolean parameter tells the method
* whether the Xlet has to obey this request. If the
* value of the parameter is true, the Xlet must
* terminate and the runtime system will assume that
* when the method returns, the Xlet has terminated. If
* the value of the parameter is false, the Xlet can
* request that it not be killed, by throwing an
* XletStateChangeException. If the MHP middleware
* still wants to kill the Xlet, it should call
* destroyXlet() again with the parameter set to true.
*/
public void destroyXlet(boolean unconditional)
throws javax.tv.xlet.XletStateChangeException {
// Do nothing for now
}
}


Thursday, 13 November 2008

Free software development with Java

This is another presentation, about free software development using Java. These slides were used during a free software event sponsored by TchêLinux.

Download it here (in portuguese).

Cheers

Wednesday, 22 October 2008

Java Introduction Course - slides - part 3

Enterprise applications, architecture, IDE, other topics, "what now?".

Download slides here.

Tuesday, 21 October 2008

Java Introduction Course - slides - part2

JavaSE, JavaME brief overview, my first web application, Netbeans overview.
Download slides here.

Monday, 20 October 2008

Java Introduction Course - slides

You can download slides I used during the first part of Java Introduction Course here. The very simple source codes we used are included within pdf file.

Portuguese: Você pode baixar os slides do curso de Introdução à Plataforma Java aqui. Os fontes bem simples que utilizamos estão dentro do próprio arquivo.

Wednesday, 17 September 2008

Generating a report in PDF format

Hey, guys.

I apologize about all the time I was away from here. I am having a busy time with a couple of huge projects around me...

This post is just to tell people I am alive (:P) and to share a very simple and useful way to generate pdf reports using Jasper Reports.


File jsFile = new File("path_to_jasper_file");
Map parm = new HashMap(); //parms to be "sent" to report. You can use null, if you want
JRBeanCollectionDataSource jrBeanSource = new JRBeanCollectionDataSource("a collection here"); //argument is not a string...it is a bean collection
JasperRunManager.runReportToPdfFile(jsFile, "path_to_pdf_to_be_created", parm, jrBeanSource);


In this case, I am using a collection of beans as data source. Could be any other source supported by Jasper. Oh, don't forget exceptions handling.

See you soon (I hope...)

Friday, 18 July 2008

Java Community Process (JCP) membership

According to Wikipedia: "The Java Community Process or JCP, established in 1998, is a formalized process which allows interested parties to be involved in the definition of future versions and features of the Java platform."

Since its introduction, JCP has played a very important role as an open process to define the future of Java. It is the place where JSR (Java Specification Request) are discussed, and this is the reason why is so important to be part of it: you can help improve Java collaborating, giving contributions and new ideas before any feature become available or definitive.

I became a JCP member just a few days ago. I hope I can give my contribution, but I am sure I will learn much more than I will teach.

My name is there :P, check here (it is listed according to your last surname. Mine is "Silva").

Please take a look at JCP's site: jcp.org