Raphael.js: Get Value Of A Text Node

When using the Raphael.js library for SVG manipulation, setting the text of a text element is as easy as

var paper = Raphael(10, 50, 320, 200);
var textEl = paper.text("My Text", 0, 0); // create a new element

// and later if we want to update the text
textEl.attr('text', 'My New Text');

However, getting the current text in this node is not as straight forward. The library dictates you should do something similar to var currentText = textEl.attr('text');, but logging that to the console outputs an Object and not a String. I’ve searched the net for months for the answer to this, and the solution I finally came up with today, after inspecting the DOM and seeing the elements being returned, is as simple as

var currentText = textEl[0].attr['text'];

The reason it needs to be this way is because the library treats the text node as a “Set” of two text elements instead of a simple HTML Element with inner text. I hope I’ve helped someone today. Happy JS Development, y’all.

Wishlist: Windows 8 Desktop Modes

I’ve been using the Windows 8 Developer Preview for a little over two weeks now, and I’m pretty pleased with it overall. I’ve managed to load up Netbeans, WAMP Server, Opera and several other niceties that I use on a daily basis and everything is chugging alone nicely without complaint. The only thing about Windows 8 that is a bit awkward is launching applications whiles in the Windows 7 Environment. Continue reading Wishlist: Windows 8 Desktop Modes

Something I Would Love To Do In Java

Java is a pretty cool language, and I think it is good for teaching the basics about programming. The following is just something I look forward to doing in future versions of Java if Object literals are added.

Here is how u define a rectangle in JavaFX using Java at the moment

Rectangle rect = new Rectangle();
   rect.setFill(Color.RED);
   rect.setWidth(200);
   rect.setHeight(100);
   rect.setX(20.0f);
   rect.setY(20.0f);

Here is how I would love to be able to define it,

Rectangle rect = new Rectangle({
   fill: Color.RED,
   width: 200,
   height: 100,
   x: 20.0f,
   y: 20.0f
});

I believe I have been spoiled by my usage of Javascript, and I could use other VM languages, but I think this is just fun to look at. This inherently has issues, because there would need to be to be a lot of Type Casting in order to get the variables out or to set them accordingly, because the Map passed as the argument would need to be defined as HashMap<String, Object> to ensure any value could be passed. The implementation of the Rectangle class would then need to internally map these properties to the right variables somehow.

With Collection Literals in Java 8 onwards, this all will be possible, but the other issue would be if the various UI Classes like Rectangle would be refactored to make the above code possible. I highly doubt it personally, but nothing is impossible.

I will certainly play around with this a bit later. Feel free to share your own ideas in the comments below.

Oracle Did Not Get The Memo About Annoying Users

Oracle recently release Netbeans 7.1 Beta and JavaFX 2.0 and made them available for download from javafx.com. I managed to get the download for Netbeans 7.1 Beta last night without fuss and completed the installation, also without fuss. I expected the JavaFX SDK to be bundled, but it was not.

Trying to download the SDK has become an exercise in futility as I’m presented with Login screens, failed login attempts, password resets and lastly server error pages. Switching browsers from Opera to IE gave me more than an error page and at least enabled me to access my Oracle accounts to reset my password, but the download for the JavaFX 2.0 still gives me an error message at the time of writing.

Whiles struggling with all this, I took time to read the introduction to FXML development for JavaFX 2.0 and compared it to Javascript /XAML development for the Win 8 applications and realized a vast similarities. It would be interesting to see which is the dominant application platform a year from now.

Oracle need to understand that if they want people (developers) to adopt a product they need to make it available without hassle, and then provide compelling services on their website where people can choose to register to be a part of. Even Microsoft are giving away downloads of the Win 8 OS without the need for an account. Oracle need to step up and move away from bureaucratic thinking and get with the programme.

Enough ranting, going back to try the download again.