Eclipse 3.4 - Templates and Save Actions

My save actions settings in Eclipse 3.4My save action configuration in EclipseSave actions are actions which are performed when a file is saved, duh?. The configuration can be found by pressing ctrl+3 and typing 'save actions' (Java > Editor > Save Actions).

The very first time I used Emacs I remember thinking, why would anyone use this? But the more I learned about how to configure Emacs the more i liked it. Nowadays it's on my top 10 list of things i would bring to a deserted island.
The point is, the less time you spend struggling with the editor the more time you can spend on developing. Having a properly configured IDE will speed up your development significantly.
I'm not going to list a bunch of hotkeys in this post. Instead I'm going to show the settings for 'code templates' and 'save actions' that I use.

Code templates

Both code templates and regular templates can be exported after they have been configured, which makes them easy to apply to new workspaces. The code template configuration can be found by pressing ctrl+3 and then typing 'code templates' (Java > Code Style > Code Templates).

Method body

It's so easy to use the 'add unimplemented methods'-feature in Eclipse that you sometimes forget that you also need to implement the methods. To make sure unimplemented methods aren't executed replace the existing template with one that thrown an exception when it's called.
throw new UnsupportedOperationException("The method ${enclosing_type}.${enclosing_method} is not yet implemented")

Catch block body / Code in new catch blocks

A better default solution for the catch blocks is to wrap and rethrow the caught exception in a RuntimeException. Don't forget to edit both templates.

throw new RuntimeException(${exception_var});

Templates

These templates are generic templates and can be invoked by pressing ctrl+space in the editor. They are found by pressing ctrl+3 and typing 'templates - java' (Java > Editor > Templates).

Log

The only templates i use are logging templates because log-lines are so tedious to write. The first template creates a static final log object with commons logging:

Name: log
${:import(org.apache.commons.logging.Log, org.apache.commons.logging.LogFactory)}
private static final Log log = LogFactory.getLog(${enclosing_type}.class); 

The second template creates a one line log that can be used inside a catch block:

Name: logerr
${:import(org.apache.commons.logging.Log, org.apache.commons.logging.LogFactory)}
LogFactory.getLog(${enclosing_type}.class).error("${cursor}", ${exception_variable_name});

Save Actions

These are my settings right now. The @Override option is really useful for detecting inheritance problems and the rest of them basically just improves readability. I don't think they need any further explanation than that.
  • Convert control statement bodies to block
  • Add final modifier to private fields
  • Add missing '@Override' annotations
  • Add missing '@Deprecated' annotations
  • Remove unnecessary casts
  • Remove trailing white spaces on all lines

Read more

Eclipse documentation Google on code templates

KB927917

Today i ran into this warning when testing IE7 compatibility for a web project:

Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)

The problem is that the site has some JavaScript code that tries to modify the parent of a DOM-node from the a child node before the child is finished loading. Here's a short example of a how to get the error:

The content will still be replaced but with a warning in the console. To get rid of the warning just move the script out to the parent container, ie.

OR, even better, use body.onload or jQuery(document).ready.
If you want more information about this problem head over to Microsoft's support site:
http://support.microsoft.com/default.aspx/kb/927917

jsTagCloud - JS canvas 3D tag cloud

jsTagCloud is a tag cloud plugin for jQuery. It uses the canvas element to render a 3d cloud that can be rotated with the mouse. It's made as a proof of concept, but it would be great if this someday evolved into a Wordpress plugin. So far i've only been able to test it in these browsers:
  • Firefox/3.0.10 - Ubuntu 9.04 x64
  • yes, only one

The tags in the demo is from this page and they should be clickable as well. The configuration of the plugin should be pretty obvious if you take a look at the source of demo.html.

Features

  • It's made as a jQuery plugin.
  • Navigate the 3d cloud with the mouse pointer
  • Clickable links
  • I just wanted more than 3 items on my feature list :)

Download and demo

The source can be found at:
https://projektserver.se/svn/tiny/javascript/jsTagCloud/
And a demo can be found at:
http://slackers.se/resources/demo/jsTagCloud/demo.html

FAQ

q: Why is the text size jumping?
a: Because i couldn't find any way to scale strings between integer font sizes
q: Can the tags be ordered by the number of items using them, just like in the cloud to the right?
a: No, everything is placed on a unit sphere with the help of our friendly PRN-generator.
q: The selection seems to be off, what's up with that?
a: Yes, sometimes the selection is a bit off. Don't really know why right now.

Simple 3d engine with JavaScript canvas

This weekend I was testing the canvas element in JavaScript. It was pretty easy so I decided to make a very simple 3d engine. The engine only consists of a simple scene graph where the camera is fixed at origo and pointing along the Z-axis. The "pipeline" consists of two steps, transformation and rendering.

All transformations are represented by 4x4 matrices which are pushed to a matrix-stack as the code traverses the scene graph. After the transformations are done the scene is rendered. The renderer only supports solid faces and edges. Since the objects aren't sorted before they are drawn all faces and lines are transparent.

I never got the inheritance to work properly in JavaScript so there is no base class for objects just one implementation of a cube-class.

A demo of the engine can be found at:
http://slackers.se/resources/demo/j3d/demo.html

The latest source is available in the project repository at:
https://projektserver.se/svn/tiny/javascript/j3d/

Install a git server on ubuntu

Finally I took the time to install a git repository with gitosis on my server. If you read the instructions carefully from the start, the install will go pretty smooth. These are the guides i used:

http://blog.agdunn.net/...
http://www.urbanpuddle.com/...
http://scie.nti.st/...