I've been a zone leader with DZone since 2008, and I'm crazy about community. Every day I get to work with the best that JavaScript, HTML5, Android and iOS has to offer, creating apps that truly make at difference, as principal front-end architect at Avego. James is a DZone Zone Leader and has posted 639 posts at DZone. You can read more from them at their website. View Full User Profile

Beautifying JavaFX Script From NetBeans Using AutoIt

11.30.2009
| 9997 views |
  • submit to reddit

NetBeans is the official IDE for JavaFX development. However, the latest v6.71 (or beta 6.8) of NetBeans is unable to beautify JavaFX Script (JfxScript) code as the “Format” option is not working (It just do nothing.  See Bug acknowledgement).

 Editors Note: This content was submitted by geekycoder

The code beautifier is one of the most important tools for learning and using  JavaFX as most raw code copied from Internet/ebook tends to be unformatted, making it hard to read and use. Performing manual format is just too tedious. So until the next NetBeans’s release, users have to resort to using painstakingly manual code formatting .

Code beautifier turn this (The following JfxScript code is formatted in NetBeans ! Read on to see how it’s done.)

image

into this

image

Introducing AutoIt Script

image AutoIt Script is a productive and powerful FREE Windows automation utility with scripting capability using a simple easy-to-use BASIC variant language. Now with AutoIt Script, users no longer have to sweat the formatting stuff.


Watch how AutoIt Script perform its magic.

AutoIt Script accomplishes it in just seconds.

How it works

The JavaScript code beautifier in NetBeans is surprisingly able to format the JfxScript code extremely well.  Therefore, AutoIt Script leverages on this “discovered” capability to automate the formatting by copying the JfxScript code to a opened Javascript file for beautifying, and then replace original code. This is all done through keystroke simulation, and takes just few seconds. With NetBeans’s undo feature, you can also undo the formatting instantly.

 

Instructions

The following download includes the source code, dummy file and 32bit executable compiled script. If you need to run in 64bit, you need to download the AutoIt environment to either recompile the source or run the source with AutoIt interpreter.

Please perform the important steps before using the script.

IMPORTANT #1:
You need to keymap the <Open File> menu Item to <Ctrl+F10> keys.

Go to:      

Tools –> Options –> KeyMapimage

 

IMPORTANT #2: 
Create a empty file called dummy.js or copy one from the following zip file  into <c:\temp> dir. This dummy file is used as a proxy to format code.

You can customize the keymap keys and dummy file through the script source from the following lines:

Local $keyBeautify = "^{F2}" ; Default to Ctnl + F2
local $keyOpenFile = "^{F10}" ; Open file, default to Ctnl + F10
Local $dummyJsFile = "c:\temp\dummy.js" ; Dummy JS file

 

If you experience some problems making it work, play around with the delay. Increase the delay in the sleep function (eg sleep(330) ). The argument is in millisec.

 

Unzip the following file and run <netbeans_beautify_jfxscript.exe>

The AutoIt trayicon (blue A icon) will appear. Now you can go to NetBeans source code editor and invoke <Ctnl+F2> to format the JfxScript code !

To exit, click on the icon again and choose Exit.

image image

 

Contents of file:

image

  code_beautifier.zip (272kb)

Tags:

Comments

Mike P(Okidoky) replied on Mon, 2009/11/30 - 11:17am

It would look *much* more readable if the braces were lined up nicely. It's very unfortunate that people follow the K&R bracing style religion so closely.

GeekyCoder coder replied on Mon, 2009/11/30 - 3:19pm

The "Format" from latest Netbeans Rc1 is now working. It is now able to format the code. However, there is still bug in it. One bug is that if the type of variable declaration  is qualified by the package, the formatting will not work properly.

For example,

public class TestClass {
    public var myDate:java.util.Date = new java.util.Date(); // myDate:java.util.Date will cause problem to formatter

   public var myString:java.lang.String = "Still buggy";
}

will be formatted as 

public class TestClass {

    public var myDate: java  
       
.util.Date = new Date();
    public var myString:java.lang.String = "Still buggy";
}

The JavaFX Script Code formatter will jumble up the first occurrence of the declaration line with package qualifier (eg myDate:java.util.Date) . If you going to use the formatter, do avoid using declaring variable with type with package qualifier.

 

My workaround still work without the above issue.

 

 

 

Mike P(Okidoky) replied on Mon, 2009/11/30 - 5:02pm

Is it possible to view and edit source files in your own preferred format (Allman), and when saving, have it automatically convert to comply with whatever crappy indentation religion a place dictates (eg. K&R).

ps. do people have any idea how much easier *especially* JavaFX code looks in Allman style over K&R, or does the doctrine dictate that less code lines is better (which it isn't). It's not that we have to save on paper for magazine printing these days, so it's one and only advantage is no longer...

GeekyCoder coder replied on Tue, 2009/12/01 - 12:42am

Mike P,

You can configure your desired style in NetBeans Rc1 under Brace Category in 

Options => Editors => Formatting => Language: JavaFX .

 That is what you looking for.  

 

 

 

 

 

GeekyCoder coder replied on Tue, 2009/12/01 - 12:43am

Correction:

Tools => Options => Editors => Formatting => Language: JavaFX .

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.