Original article: http://hiperia3d.blogspot.com/2008/04/netbeans-tutorial.html [1] (the original article has coloring that makes reading easier. If you have some dificulty reading it here, you can go there).
The process of creating the first of the modules that compose my X3DV Module Suite [2] was similar to the one described here.
We will learn how to make a module that has these features:
Create a new NetBeans project:
[4]
Choose NetBeans Modules in Categories and Module in Projects:
[5]
Fill in your project Name, locate the directory where its project folder will be placed, and mark it as a Standalone Module.
[6]
Fill the info for your module. You just have to fill the two first text boxes: change the Code Name Base to what is appropriate for your module and choose a Display Name.
[7]
The project will be created. Now we will add the basic: support files for the new file type.
[8]
Over the project name, right click and select New/File Type:
[9]
In the dialog that appears, you must enter some data so the NetbBeans IDE recognizes the new file type.
In MIME Type you must enter text/x- usually followed by the main extension of the file type.
Why does it say text/x-? As you may note, what you enter is not the true MIME type. For the IDE, all the extensions we create are text files.
In Extension(s) you must enter them separated with spaces. In our example, there's only one extensions for Foo Files: .foo
[10]
In Class Name Prefix, you enter the name of the file type, so all classes generated by the IDE for this module will start with it.
In Icon, you must locate in your hard drive a gif icon of 16x16 pixels. In our example, it's this:
[11]
Although
in some tutorials they say that jpg and png images can also be used, I
found that sometimes they're not displayed. So I recommend using gif
images, as they are less error-prone.
The IDE will copy your icon to the project directory.
[12]
At
this point, a bunch of files will be created by NetBeans IDE and opened
in the code editor. Close them all, you don't need to edit them.
Now
our module is ready to recognize and create the new file types. But we
want the new files to have a default content. So we will edit the
generated template. Locate the file named:

[13]
[14]
[15]The
next step is to create a description of the new supported file type
that will be displayed when you want to create it, in the New File
Wizard. This description will be stored in a file called
"Description.html" (strange... uh?).
Add this line after the one highlighted in blue, modifying it to your project url:
[16]
[17]
[18]Now that we have the new files recognized, we will add syntax coloring and other features to our language module.
To
be able to support language features, we must do the following: right
click over your project and choose "Properties". The properties of your
module will be displayed. Click over libraries (on the left) and then
the "Add..." button.
[19]
In the list, search for the entry called "Generic Languages Framework", and add it.
[20]
Now, right click over your project and select New/Other.
In Categories, select "Module Development", and on the right, select "Language Support".
[21]
Then enter the MIME Type and Extensions as we did in the first section of our tutorial.
[22]
You
will see that the XML Layer has changed and now has more things added.
Between them, there's a new file that describes our language. That file
is called "language.nbs".
As the XML Layer has been modified,
the icon of our files may have disappeared, so we need to add something
to the XML Layer file to recover it.
Close all the opened files. Locate the file called XML Layer, and open it. Locate the line highlighted in blue in this image, that says
[23]The
default language.nbs file is filled with contents that may be a good
start point for a scripting language. For declarative languages like
VRML or X3D, or markup languages like HTML or similar, these contents
are not useful.
In our example of the Foo Language, we will use
a very simple language definition. This way you will understand the
basics of defining languages.
So delete all the contents of the file language.nbs, and replace them with this:
# To change this template, choose Tools | Templates
# and open the template in the editor.
# definition of tokens
TOKEN:header:( "# foo language v1.0"
)
TOKEN:line_comment: ( "#"[^ "\n" "\r"]* |
"//"[^ "\n" "\r"]* )
TOKEN:keyword:(
"foo_function" |
"foo_command"
)
TOKEN:field:(
"foo_value"
)
# all that follows is useful for mostly all languages
TOKEN:identifier: ( ["a"-"z" "A"-"Z"]
["a"-"z" "A"-"Z" "0"-"9" "_"]* )
TOKEN:number: (["0"-"9"]*)
TOKEN:operator: (
":" | "*" | "?" | "+" | "-" | "[" | "]" |
"<" | ">" |
"^" | "|" | "{" | "}" | "(" | ")" |
"," | "=" | ";" |
"." | "$"
)
TOKEN:string:(
"\""
(
[^ "\"" "\\" "\r" "\n"] |
("\\" ["r" "n" "t" "\\" "\'" "\""]) |
("\\" "u" ["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"])
)*
"\""
)
TOKEN:string:(
"\'"
(
[^ "\'" "\\" "\r" "\n"] |
("\\" ["r" "n" "t" "\\" "\'" "\""]) |
("\\" "u" ["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"]
["0"-"9" "a"-"f" "A"-"F"])
)*
"\'"
)
TOKEN:whitespace:( [" " "\t" "\n" "\r"]+ )
# colors
COLOR:header:{
foreground_color:"orange";
background_color:"black";
font_type:"bold";
}
COLOR:line_comment:{
foreground_color:"#969696";
}
COLOR:keyword:{
foreground_color:"red";
font_type:"bold";
}
COLOR:field:{
foreground_color:"#25A613";
font_type:"bold";
}
# parser should ignore whitespaces
SKIP:whitespace
# brace completion
COMPLETE "{:}"
COMPLETE "(:)"
COMPLETE "\":\""
COMPLETE "\':\'"
# brace matching
BRACE "{:}"
BRACE "(:)"
# indentation support
INDENT "{:}"
INDENT "(:)"
# foo language v1.0Now let's see the language.nbs file and understand the basic parts.
# comment
// another comment
foo_function {
foo_command ( foo_value 1 0 1 );
}
# brace completionWhat these lines do is that when you type a { sign, the editor automatically will type } after your caret, speeding your work and making it less error-prone.
COMPLETE "{:}"
# brace matching
BRACE "{:}"
# indentation support
INDENT "{:}"
Now you know all that is needed to create the basic support for a new file type and language syntax highlighting.
You can add anything you like to your module, that you think is important for you and that could make your work easier.
There's
much more than can be done with NetBeans IDE. I invite just to test it,
join its huge community of users, and experience it by yourself.
-Jordi R. Cardona-
X3D/VRML Worldbuilder
Java Programmer
X3DV Module Suite Developer.
Hiperia3D News [24]
© 2008 by Jordi R. Cardona. The images and text of this post were added by the author to dzone. The author has granted dzone.com with exclusivity to use these images and text for the only purpose to spread this article. If you want to promote this tutorial, you can link to the original one at: http://hiperia3d.blogspot.com/2008/04/netbeans-tutorial.html [25]
Links:
[1] http://hiperia3d.blogspot.com/2008/04/netbeans-tutorial.html
[2] http://hiperia3d.blogspot.com/2008/01/x3dv-module-for-netbeans.html
[3] http://download.netbeans.org/netbeans/6.1/beta/
[4] http://bp1.blogger.com/_9lcs1G94AbE/R_viylsWOlI/AAAAAAAAAUM/xiyWABFQEYw/s1600-h/01_Netbeans_Tutorial.jpg
[5] http://bp0.blogger.com/_9lcs1G94AbE/R_viwVsWOkI/AAAAAAAAAUE/RTKxIL4SU8M/s1600-h/02_Netbeans_Tutorial.jpg
[6] http://bp3.blogger.com/_9lcs1G94AbE/R_visFsWOjI/AAAAAAAAAT8/uOP0sDYA-1k/s1600-h/03_Netbeans_Tutorial.jpg
[7] http://bp3.blogger.com/_9lcs1G94AbE/R_vicFsWOiI/AAAAAAAAAT0/npUHlXXyKdk/s1600-h/04_Netbeans_Tutorial.jpg
[8] http://bp1.blogger.com/_9lcs1G94AbE/R_viQlsWOhI/AAAAAAAAATs/wyAEYSJ3bik/s1600-h/05_Netbeans_Tutorial.jpg
[9] http://bp3.blogger.com/_9lcs1G94AbE/R_viJFsWOgI/AAAAAAAAATk/dVeWslguk-M/s1600-h/06_Netbeans_Tutorial.jpg
[10] http://bp0.blogger.com/_9lcs1G94AbE/R_viGVsWOfI/AAAAAAAAATc/X1U-IyTiv1c/s1600-h/07_Netbeans_Tutorial.jpg
[11] http://bp2.blogger.com/_9lcs1G94AbE/R_0HM8c8YAI/AAAAAAAAAUU/6whPEI84yvA/s1600-h/foo_gif.gif
[12] http://bp1.blogger.com/_9lcs1G94AbE/R_0NDsc8YBI/AAAAAAAAAUc/NiDaNqbp4Ms/s1600-h/1.jpg
[13] http://bp0.blogger.com/_9lcs1G94AbE/R_0OTcc8YDI/AAAAAAAAAUs/_Ee0sNMerx0/s1600-h/3.jpg
[14] http://bp3.blogger.com/_9lcs1G94AbE/R_0OuMc8YEI/AAAAAAAAAU0/n_AVi-i_YQw/s1600-h/4.jpg
[15] http://bp2.blogger.com/_9lcs1G94AbE/R_vhx1sWOaI/AAAAAAAAAS0/De54y0s13C4/s1600-h/12_Netbeans_Tutorial.jpg
[16] http://bp3.blogger.com/_9lcs1G94AbE/R_0PVMc8YFI/AAAAAAAAAU8/WZE1iRUthdU/s1600-h/5.jpg
[17] http://bp0.blogger.com/_9lcs1G94AbE/R_0P0cc8YGI/AAAAAAAAAVE/xPXSmadqblw/s1600-h/6.jpg
[18] http://bp3.blogger.com/_9lcs1G94AbE/R_vhUFsWOXI/AAAAAAAAASc/Rmvc4vzqzEc/s1600-h/15_Netbeans_Tutorial_ejemplo de lo que hace.jpg
[19] http://bp2.blogger.com/_9lcs1G94AbE/R_vhN1sWOWI/AAAAAAAAASU/fdqgy-hUyJw/s1600-h/16_Netbeans_Tutorial.jpg
[20] http://bp1.blogger.com/_9lcs1G94AbE/R_vhLlsWOVI/AAAAAAAAASM/_Q7VUPqkgSo/s1600-h/17_Netbeans_Tutorial.jpg
[21] http://bp0.blogger.com/_9lcs1G94AbE/R_vhFVsWOTI/AAAAAAAAAR8/-NatKLXHtp0/s1600-h/19_Netbeans_Tutorial.jpg
[22] http://bp2.blogger.com/_9lcs1G94AbE/R_vg_1sWOSI/AAAAAAAAAR0/3wVS6TyK5uo/s1600-h/20_Netbeans_Tutorial.jpg
[23] http://bp0.blogger.com/_9lcs1G94AbE/R_vgyVsWORI/AAAAAAAAARs/83r1P24MmhU/s1600-h/21_Netbeans_Tutorial.jpg
[24] http://hiperia3d.blogspot.com/
[25] http://hiperia3d.blogspot.com/2008/04/netbeans-tutorial.html