Posts

Showing posts from May, 2008

NetBeans plugin: Special copy/paste

Image
The very little I've had to paste code into this fairly new blog, was enough to give me the idea of creating an extension to NetBeans which would help to remedy this formatting nightmare. Now, in my world, there's approximately a 100:1 ratio between idea and actual realization, so I'd have to salute the awesome OpenIDE API's for making this possible spending just a few late nights and taking just 200 lines of code. Without further ado, I present, my first NetBeans plugin . Special copy/paste The plugin will add a couple of new actions to the context-sensitive popup-menu of the source editor, which will allow you to copy the selected text as preformatted HTML, as well as a CSS version which will preserve the formatting used in NetBeans. Using the "Copy as HTML and CSS" menu as in the above screen dump will result in you being able to paste it directly into a website/wiki/blog and have it display like this: /** * @param args the command line arguments

Keurig Platinum B70

Time to try to live more up to the name of this blog. As most developers, I have a passion for coffee and coke and consume it in quantities which are probably not on the healthy side. Anyway, when I saw the Keurig Platinum B70 coffee maker in action, I absolutely had to own one. Why? Take a look below. Yup, it takes 45 sec. for it to brew a large cup (4 sizes to choose from) of fresh programmer oil, has a very gadgety blue light and is ready to serve its master 24/7. It probably isn't the most economical way to get your caffeine dose, but it does allow for a small filter so that you can use normal coffee beans rather than the convenient K-cups. Also, it came with samples of Van Houtte's Kenyan Kilimandjaro roast , so now I know why Stephen Colebourne named his OpenJDK sandbox Kijaro . ;)

Type registry strategy pattern

One pattern that I have often seen applied in Java, is the one where you plug-in and register a handler for a given type of object to thereby supply a specific behavior for it. For instance, this is often used in order to render, edit and validate elements of various visual components in Swing, such as the JTable. I am unaware of any official name for this mechanism, but it appears to be a combination of Martin Fowlers Registry Pattern and the GoF Strategy pattern so I like to think of it as the Type registry strategy pattern. Legacy example Conditional behavior is encapsulated by some common interface, which provides the mechanism for dispatching to elsewhere, responsible for applying a concrete strategy. An example is this format handler, which allows an object to be formatted as a String: 1 interface Handler 2 { 3 String format(Object object); 4 } And an API, capable of associating handlers for various Object types registered and dispatching to these: 5 class SomeAPI 6 {

@SuppressWarnings values

Image
Meta-data and how to associate it has always been a bit of a confusing topic in Java. For instance, the transient modifier is really a kind of marker annotation, as is the @deprecated javadoc tag compilers are also required to process, as is the marker interface Serializable. Then in JDK 1.5, a dedicated annotation facility was added, probably in light of the success of C#'s attributes. One of the first practical uses of annotations appears to be as a way to suppress compiler warnings. @SuppressWarnings This build-in annotation allows the developer to signal a respecting compiler that it should forgo a particular warning. It can be applied in front of a type, a field, a method, a parameter, a constructor as well as a local variable. It is up to the compiler to make sense of whatever you put inside the String, the only value mandated by the JLS is the "unchecked". Compilers as well as IDE's will typically implement each their own set of warning types, the Eclipse IDE d