The Source for Java Technology Collaboration
User: Password:



Bruno Ghisi's Blog

Community: NetBeans Archives


Starting with Sun SPOT using NetBeans 6.1

Posted by brunogh on April 11, 2008 at 09:41 PM | Permalink | Comments (6)

If you do not have a Sun SPOT (Figure 1), do not be bored, you can still have a lot of fun! In this entry, I gonna explain how to start programming the world using NetBeans 6.1!



sun_spot2.jpg

Figure 1: Sun SPOT rulez!!!


Downloading NetBeans IDE 6.1


1. Download NetBeans IDE 6.1 (RC1 launched today). A lot of new nice features, take a look in the New and Noteworthy and in the release page for a detailed list.


Installing Sun SPOT plugin


2. Install Sun SPOT plugin into NetBeans. Download com-sun-sunspot-updatecenter.nbm. Now, in NetBeans, go to:
2.1 Tools menu -> Plugin.
2.2 Click on Downloaded tab.
2.3 Click on Add Plugins button and select the file. Then, confirm the installation clicking on Install button and accept the license agreement.
2.4 Finally, go to the Available Plugins tab, mark SunSPOTApplicationTemplate, SunSPOTHostApplicationTemplate and Sun SPOT Info, click on Install button and accept the license agreement.
2.5 You can check that everything is installed going to Installed tab (Figure 2).


PS: David Simmons has blogged about these steps before.


netbeans_spot1.png
Figure 2: Installed tab.


Getting Sun SPOT SDK 3.0 Beta


3. Get the Sun SPOT SDK 3.0 Beta emailing David Simmons, more details here. You will receive a link to download SPOTManager tool, that is a jar that installs the SDK and can run the emulator. Be sure you have at least JDK 1.5 and at least Ant 1.6.5 installed and configured in your system.


Creating the Demo Application


4. Let's make the default demo application work. Go to:
4.1 File menu -> New Project
4.2 Select Java category, select Sun SPOT project and then click Next.
4.3 Leave the default project name and package and click Finish.
4.4 Open org.sunspotworld.StartApplication.java. You can see it extends MIDlet and already has some code. If you are familiar with Java ME, you will not have big problems. But, basically, Sun SPOT arquitecture is CLDC (Connected Limited Device Profile) 1.1 and has IMP (Information Module Profile) in the top - which can be defined as a MIDP (Mobile Information Device Profile) without UI stuff. Also, it has some additional libraries and all this runs in a VM called Squawk, that is characterized by being most written in Java. So, StartApplication implements the abstract methods inherited from the MIDlet (startApp,pauseApp that Squawk never calls and destroyApp). It works in a sand box enviromnent.


The startApp code, in List 1, basically gets an object reference to the singleton eDemo Board and then make its LED blink red for a quarter of second each second. As you, can see, the code is pretty high level and easy to understand.



protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello, world");
new BootloaderListener().start(); // monitor the USB (if connected) and recognize commands from host

long ourAddr = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr));

ISwitch sw1 = EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
leds[0].setRGB(100,0,0); // set color to moderate red
while (sw1.isOpen()) { // done when switch is pressed
leds[0].setOn(); // Blink LED
Utils.sleep(250); // wait 1/4 seconds
leds[0].setOff();
Utils.sleep(1000); // wait 1 second
}
notifyDestroyed(); // cause the MIDlet to exit
}


List 1: startApp code.


Running the Demo Application in the emulator


5. Put this application to run in the emulator.
5.1 Right click the project and select Build. It will generate the jar in the /$PROJECT_HOME/suite/. If you have a spot device, you could send it directly by right clicking the project and selecting Build Project + Deploy to Sun SPOT , forgetting the next steps.
5.2 Open the emulator (in the ToolManager, go to Solarium tab and then click in the Solarium button). Then, in the emulator, click on the Emulator menu -> New virtual SPOT, you will notice that a Sun SPOT will appear in the squared right area.
5.3 Right click on the Sun SPOT picture, then click Specify application jar file... and select the application jar in /$PROJECT_HOME/suite/, which is the place that the application was built in step 5.1.
5.4 After that, click again on it, then Run MIDlet and StartApplication. Finally, you will see a red LED blinking!!! Wow!



netbeans_spot2.png

Figure 3: NetBeans 6.1, ToolManager, Emulator and the red LED blinking!


Where I go next?


In NetBeans, check the Sun SPOT Info, that you have installed with the plugin, by clicking in the Window menu.
David Simmons' Blog - http://blogs.sun.com/davidgs
Roger Meike's Blog - http://blogs.sun.com/roger
Sun SPOT Feeds (really nice aggregator with more cool blogs) - http://planets.sun.com/SunSPOT/group/SunSPOT
Project Sun SPOT - https://www.sunspotworld.com
Open source Sun SPOT - https://spots.dev.java.net (take a look in its subprojects as well).
Search for spaughts in youtube.com or subscribe the tag feed directly.
Recently, Aaron Houston has organized a conference call about Sun SPOT with Roger Meike and published the nice links we get during it in an email he sent. The links are available here too. Slides here.




PS: I am using this entry for the NetBeans IDE 6.1 Beta Blogging Contest, take a look at http://www.netbeans.org/competition/blog-contest.html for more information about it. Go ahead, make an entry and have a chance to win $500! Good luck for us!




61blog-contest-logo.gif




Thanks! Have a nice weekend!


Program the world!


Bruno Ghisi



Building a Java ME Bluetooth chat in 12 minutes...

Posted by brunogh on April 02, 2008 at 08:05 PM | Permalink | Comments (0)

As it was announced before, Marge 0.5 is out. In this post, I am going to demonstrate an interesting new feature called AutoConnect. AutoConnect is indeed to automatically connect Bluetooth devices. It has some limitations due to some bad implementations and has some scenarios that maybe it is not the best option, but still very interesting and is definitely awesome to make something with a few lines of code! For more information about the new release and this feature, please check http://wiki.java.net/bin/view/Mobileandembedded/HowTo05.

So, nothing better than show a video... [sometimes I think I should have done cinema :) ]... Anyway, if you have not seen any Marge videos yet, try "Project Marge Interview", "My laptop is detecting my presence" and "Giant Blue Pong (my Bluetooth Atari)". Too much talk, take a look at the new "Building a Java ME Bluetooth chat in 12 minutes..." too. Could you not understand what happened in Netbeans code editor? Neither do I!!! It is better to download the full video (30MB). Hope you enjoy!

marduke.png

If you want more about Marge, go to http://marge.dev.java.net. If you want to help, please send an email to owner@marge.dev.java.net. We would love to hear suggestions and have you in our team!

Go ahead! Marge your Bluetooth app!



My First JRuby Bluetooth App

Posted by brunogh on January 31, 2008 at 06:54 PM | Permalink | Comments (6)

TV, Coke and a laptop, it is time to have fun!

We are always trying to integrate Marge (Java Bluetooth Framework) with other things. If you remember, in a last post, JavaFX Script was used, now it's time for JRuby! May you don't know, JRuby is Java implementation of the Ruby programming language. I am not a Ruby expert, but I hope I can become, because I am enjoying the language so much. Actually, I enrolled in a pretty interesting free online course by Satish Talim. If you enjoyed the content, be sure you join on March too!

Here we go, no more delays! The basic idea of this post is to show a simple sample application that inquiry for Bluetooth devices, but more than just creating the application, be aware of thinking in the possibilities you can have with JRuby.

What you will need:
  • Download Netbeans IDE 6 (Select All package version, because it comes with Java and Ruby).
  • Get marge-core in Marge repository (you can use Netbeans to checkout from Subversion and generate a jar, because the last version is under development and was not launched yet, we are working on it :) ). Otherwise download the last launched version (0.4.0) and fix the inquiry method.
  • Get a JSR 82 implementation, I have used Avetana for Linux. I have explained it in another post, you can take a look here.

Time to code!
  1. Create a Ruby Project: File -> New Project -> Ruby -> Ruby Application. Click Next, configure your project (create a main.rb file and use a JRuby interpreter) and then click Finish.
  2. Add marge-core and Avetana. Right click in the project -> Properties -> Java and then add the jars in the JRuby classpath.
  3. Add the following code into main.rb. The code is pretty intuitive, because Ruby is! It basically imports some Marge classes (that are going to use Avetana internally), defines a listener that will be called during the inquiry and will print all the devices found. Also, the inquiry will be started by the singleton DeviceDiscoverer.

  4. 
    include Java
    
    include_class 'net.java.dev.marge.inquiry.DeviceDiscoverer'
    include_class 'net.java.dev.marge.inquiry.InquiryListener'
    
    puts 'Inquiring for Bluetooth Devices'
    discoverer = DeviceDiscoverer.instance;
    
    class InquiryListenerAppender 
        include InquiryListener
      def inquiryCompleted(remoteDevices)
        remoteDevices.each { |device| print "#{device.bluetooth_address} - #{device.get_friendly_name true} \n"  }
      end
      def inquiryError
        puts 'Inquiry Error'
      end
      def deviceDiscovered(device,deviceClass)
      end
    end
    
    discoverer.start_inquiry_giac InquiryListenerAppender.new
    

Project Window:
btjruby_1.png

Just insert your Bluetooth USB adapter press F6 to run!
btjruby_2.png

My mobile was found! Before we finish, take a look in this nice effort to integrate Bluetooth/Ruby.

The possibilities are endless...they are always endless...

Cheers,
Bruno Ghisi

Developing OpenOffice.org Extensions in Java!

Posted by brunogh on December 06, 2007 at 06:17 PM | Permalink | Comments (6)

Hello guys!

It's Friday! It's already December! What a great day to write about OpenOffice.org, which is lovely abbreviated as OOo. A lot of people have asked me about how mOOo Impress Controller was built. I am not too old yet - getting older this Sunday :) - but I have some stories to tell.

In the begining of this year, I was at fisl 8.0 (International Free Software Forum)*, which is one of the biggest open source Latin America conferences and happens in the south of Brazil. If you like to talk about software, open source, Linux, culture, meet people, etc, etc, etc you should be there once! The 8th edition was definitely very special, I have met a lot of nice people, including people from Mobile & Embedded Community and Louis Suarez Potts. Please, froze this part, because we will get back here later, but now I have to start a new paragraph. As you can see, this post looks like that crazy movies that goes forward and reward, starts from the end... yeah, and this entry really starts from the end, if you have looked in the RSS description, I have written "You can develop extensions for your OpenOffice.org suite... with Java! Wow! There is a huge community around it, plugins to make your life easy, good documentation... so, what are you waiting for?!"... don't worry, we will get there.

At that time of fisl 8.0, I had a very experimental demo running on Eclipse. The demo was made of two applications written in Java: a mobile (Java ME/MIDP) and a desktop (Java SE) one. The mobile was able to communicate, over Bluetooth, with the desktop side and the both used a XML protocol to interact. So, the mobile was able to navigate through the desktop file system, filtering for all the Impress OOo presentations that was being found. Also, the mobile was able to send a request to start a presentation file and after started, it was able to control the presentation, advancing and going back in the slides. It was something like that, but, as you guys know Murphy's Law, things are not always perfect and I can guarantee things get worse when you deal with demo applications. Anyway, the demo was not completely integrated with OOo, it was a just a demo invoking OOo Api. So, regarding what I have said in the last paragraph, I have met Louis and he was the guy that has gave the motivation to create a real OOo extension, after he has explained more about what was that, how Java would help that and son on.

After the event, Lucas Torri and I have completely rewritten that demo as an Add-On extension, which later was called mOOo Impress Controller. So, we are now in the main part of this entry: you can easily create OOo extensions in Java. I said easily! There are plugins for Eclipse and for Netbeans IDE (help localizing it to your language). Basically, to put any of those plugins working, you just need to install an OOo SDK and also have an OOo suite or any other compatible installed, for example, StarOffice. Just be careful with the versions to keep things working fine. Get started now! Here it goes very useful links:

Go ahead! Make something that looks like your way! Automate any task that you always wanted in your suite! Make something different! Let me know!!!

Have a great weekend!

Bruno Ghisi


* Call for Papers for fisl 9.0 are already open and goes until 20th of December. The event will be on April, 17-19 in Porto Alegre, Rio Grande do Sul, Brazil.

What's coming in NetBeans Mobility Pack 6.0?

Posted by brunogh on August 07, 2007 at 10:59 AM | Permalink | Comments (4)

Hi all! I've downloaded Netbeans IDE 6.0 M10 - M10 is the last milestone for feature development - last weekend to take a new look in the Mobility Pack 6.0 that is coming. The Mobility Pack 6.0 will be now part of the Standard and Full version of Netbeans, you do not need to install it anymore, just if you get the Basic version. Netbeans 6.0 is planned to be available in the end of the year.

So, let's talk about the news around Mobility Pack 6.0. We are definitely going to have a lot of improvements that will make ME developers even more happy! Some of things that I have noticed and tried:

  • A lot of change in UI (User Interface) stuff in order to improve usability, like in the Projects Window you will not only see the packages, but now you will see things divided into Source Package, Resources, Project Configuration.
  • Project Configuration Management was improved, so now it is easy to add Configurations and manipulate them, in order to, for example, have different deploys for your application and easily make them directly in the Projects Window.
  • Mobility Deployment Manager was upgraded to allow you to create several instances of each deployment type - such as File Copy, FTP (File Transfer Protocol) and new types that were inserted - and then associate any of these instances to a Project Configuration.
  • Web Services API (JSR 172) stub compiler was rewritten and now have support for Base64 type, it is able to parse documentation from methods and has a better generated code.
  • One of my favorites... Visual Mobile Designer (VMD) 2 is coming! In this new version, we will have a lot of improvements in terms of functionality and usability, some of them are: its UI has changed a lot (this new style looks better!), an Analyzer that shows what commands and/or resources were no longer being used and shows a MIDP-1.0 compliancy checker. You have new things in your Pallete too:
    • In Flow area (easier to make and understand MIDlets flow graphically with these new stuff!): Entry Point (represents a method), Call Point (represents a code fragment), If (flow forking based on a specific condition), Switch (similar to If but you can specify Switch Case on it), List Action (you can put in a Command, so the List containing the Command will have a method to process the List Element that was selected, by default, all the List have a Command like that, but needs to be setted true to be showed), Previous Screen Action (an icon that represents to go to the previous screen, really useful for Back Buttons).
    • Displayables area (Four new Custom Components): FileBrowser (is a List) for the JSR 75 FileConnection Optional Package, PIMBrowser (is a List) for the JSR 75 PIM Optional Package, LoginScreen (is a Canvas) for authentication purposes with username and password, SMSComposer (is a Canvas) for sending SMS (Short Message Service) easily. You can fin them at $NETBEANS6_HOME/mobility8/modules/ext/nb_midp_components.jar.
  • One of the biggest features was the merge of CDC and CLDC in a unique Mobility Pack (CDC development got a lot of evolution because of that too).
  • Game developers will like that: in this new pack we are going to have the Game Builder, which is a visual editing support for MIDP 2.0 Game API including creation and editing of Sprites, TiledLayers and their arrangement into Scenes.


For more around this fresh version, go to Mobility Milestones in Netbeans Wiki, there are detailed pages for each milestone, and VMD has its own page as well. Got curious? Download Netbeans 6.0 M10 and have a look yourself about what is coming (note that some things are still getting more stable)! Netbeans 6.0 will have a lot of other improvements, including in the code editor, which was one of the biggest complains about users of other IDEs. Great! Have a nice week!

Thanks,

Bruno Ghisi



Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds