Sep 8 2011

Packt 2011 Open Source Awards

The 2011 Open Source Awards was launched on the 1st week of August by Packt, inviting people to visit www.PacktPub.com and submit nominations for their favorite Open Source project. Now in its sixth year, the Awards continue in its aim of encouraging, supporting, recognizing and rewarding all Open Source projects.

The 2010 Open Source Award Winners included the Open Source Content Management System (CMS) Award winner CMS Made Simple, Open Source JavaScript Libraries Award winner jQuery and Pimcore the winner of the Most Promising Open Source Project Award.

The 2011 Awards will feature a prize fund of $24,000 with several new categories introduced and the vote of the public becoming more influential.

Packt has opened up nominations for people to submit their favorite Open Source projects for each category at www.PacktPub.com/open-source-awards-home. The top five in each category will go through to the final, which begins mid-September.


Aug 18 2011

NetBeans IDE 7 Cookbook Review

I just finished reading the NetBeans IDE 7 Cookbook by Rhawi Dantas.This book is a collection of recipes addressing common tasks you will face writting applications with Netbeans.

These recipes are small, direct and concise tutorials that will show you, step by step, the procedure to achieve those tasks.

There are more than 70 recipes grouped by several topics like GUI, Mobile, Web Applications, Refactoring and so on.

Each recipe has four different sections: an introduction, the how-to of the recipe, a description of how it works, and some text about additional things or procedures you can use to extend the procedure of the addressed task.

You can download a free sample chapter to get an idea of how the recipes are written.

One of the good things of the book is that it is not bound to any language at all. It shows all the main features of Netbeans available for any language and technology, covering how to create the projects and how to use the common tools to all the languages and some others that are language specific.

In the other hand it does not cover all the things you can do with Netbeans (obviously!), but is a good introduction of the main things you will find on the IDE.

I have to say that I am a Netbeans user since 2005 and I am very used to it. With that in mind, I feel this book is not well suited for advanced users or people already familiar with Netbeans.

That is not necessarily a bad thing. The book is indeed for those coders who are making their first steps into this IDE and need a tutorial for quickly getting things up and running.

All in all, this is a very valuable book for beginners or for people that is currently starting up with Netbeans. It will teach you the basics steps to quickly start developing applications with Netbeans.  The concepts and recipes are basic so more advanced users may want to pass.


Jul 27 2011

Now reading Netbeans IDE 7 Cookbook

Thanks to the people at Packt Publishing I’m currently reading the Netbeans IDE 7 Cookbook that was recently released coinciding with the release of Netbeans 7.

It’s looking quite good, and seems to be a nice collection of solutions and a good starting point for Netbeans newcomers.

Once I’ve finished reading it I will be writing a review here so stay tuned.


Sep 7 2010

Netbeans Platform book

I came across a new book from Packt Publishing about Netbeans Platform.

In some of my game projects I have the need to write some custom editors, (world editors, material systems, particle editors, AI tweaking…)

Although I am very used to make my game editors in C#, Netbeans Platform could be a very valuable option to write this kind of editors rapidly.


Aug 28 2008

Netbeans file templates

You may have seen that when you create a new class, interface or something with Netbeans, the IDE automatically generates some code for you.

It is possible to customize this code using the Netbeans File Templates.

Under the “Tools” menu there is an option called “Templates”. This dialog let you create and edit every template used in the IDE. Just click on the “Open on Editor” button to edit the desired template inside Netbeans.

Let’s see how the Java/Class template looks like:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
*
* @author ${user}
*/
public class ${name} {

}

If you edit this file and save it, the IDE will be using your new template for every new Java class you create.

Since Netbeans 6.0 you can use the FreeMarker template language in your file templates. This way you can add logic to the templates via directives such as if/elseif/else and loop constructs.

You can also use some predefined variables:

  • ${date} — Inserts the current date, in this format: Feb 16, 2008
  • ${encoding} — Inserts the default encoding, such as: UTF-8
  • ${name} — Inserts the name of the file.
  • ${nameAndExt} — Inserts the name of the file, together with its extension.
  • ${package} — Inserts the name of the package where the file is created.
  • ${time} — Inserts the current time, in this format: 7:37:58 PM
  • ${user} — Inserts the user name.

This is an example of a modified file template for Java classes:

////////////////////////////////////////////////
/// File: ${nameAndExt}
/// Created: ${date}  ${time}
/// Encoding: ${encoding}
////////////////////////////////////////////////

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && != "">
package ${package};

</#if>
/**
*
* @author ${user}
*/
public class ${name} {

}

Aug 26 2008

Java & Netbeans: Overriding paint to customize GUI components

I found that it’s somewhat tricky to override GUI components methods with Netbeans, because the IDE automatically generates the code needed for the component, and that code cannot be edited (it’s grayed out).

But there is a property, in the “Code” tab of the component properties called “Custom Creation Code”, that let us insert the creation code we need for that component.

For example. Create a new desktop application project and, using the design view, drop a new JPanel inside the main panel. If you inspect the source code that Netbeans has generated, you can see the declaration:

private javax.swing.JPanel jPanel1;

And the initialization for that JPanel:

jPanel1 = new javax.swing.JPanel();

Note that the code after the “=” is called “Creation Code”.

Now, open the properties menu of the JPanel you have just dropped before and click on the “code” tab. Click on the “Custom Creation Code” property.

This property allow us to insert whatever code we need for the creation of the component.

Today we just want to override paint() so we insert this code:

new javax.swing.JPanel()
{
    public void paint(Graphics g)
    {
        super.paint(g);
        ourCustomPaintingMethod(g);
    }
};

If you check the generated code again you can see that Netbeans has changed the creation code:

jPanel1 = new javax.swing.JPanel()
{
    public void paint(Graphics g)
    {
        super.paint(g);
        ourCustomPaintingMethod(g);
    }
};

This way we can override any GUI component method we want ;)


Jul 7 2008

Dependency injection between two local EJBs with Netbeans

This a simple tutorial about how to create a local dependecy injection within two EJBs 3.0.

The point is creating one EJB that calls a method from another local EJB with Netbeans and Glassfish.

Start Netbeans and create a new EJB project called Util and add a new session bean to it. Make it stateless and local.



@Local
public interface UtilLocal
{
    int returnInt();
}

@Stateless
public class UtilBean implements UtilLocal
{
    public int returnSomething()
    {
        return 0;
    }
}


Now create a second EJB project called Main and add a new session bean to it, like in the Util EJB. Include the Util EJB inside the Main EJB project.



@Local
public interface MainLocal
{
    int doSomeLogic();
}

@Stateless
public class MainBean implements MainLocal
{
    @EJB(beanName="UtilBean")
    UtilLocal utilEJB;

    public int doSomeLogic()
    {
        return utilEJB.returnSomething();
    }
}


Note that we use @EJB to instantiate the Util EJB object.


Simple yet effective :mrgreen:


Jun 24 2008

J2ME Game Template

Some time ago I decided to write a simple template to facilitate the task of creating a new J2ME project.

The template is a Netbeans project that can be used as a base to build a J2ME game or application. It is ready to build projects for MIDP 1 and MIDP 2 as well as specific versions for Nokia. This can be achieved by changing simple processor directives.

The template has one thread to run the main loop. Inside this loop, the input and the screen are automatically updated in each frame.

It also has some input functions and code to detect if the device supports double buffering or not. In case it doesn’t the template manages double buffering for you.

The main functions are in MainCanvas class:


private final static void MAIN_Render(Graphics g)

private final static void MAIN_Loop()

private final static boolean INP_KeyDown(int key)

private final static boolean INP_AnyKeyDown()

private final static boolean INP_KeyPress(int key)

private final static boolean INP_AnyKeyPress()

The first two functions are where you are going to put your render and logic code. The template first calls MAIN_Loop, for your logic code, and then it calls MAIN_Render, where you draw whatever you want.

The input functions are provided for detecting if a key is down or whether it has been pressed within the last frame.

The template comes with an example of its use so you can test it and hack it as much as you may want to.

You can download the template from here­.