A free SVG for HP iPod tattoos

As seen elsewhere, HP makes these great stickers called "HP Printable Tatoos for your iPod". For your convenience, you can download template.svg, a template I created for building custom iPod skins in Corel Draw or Illustrator. Some tips: Skins are $20 for ten. That's quite expensive. If…

Logging in to a web app using JAAS on JBoss

I recently rebuild the login system for my J2EE application. I've learned a lot about JAAS, JBoss and Servlets and I'd like to share that knowledge here. JAAS login and the client-login domain There's a special login domain called client-login that passively stores your login credentials. It does not authenticate…

Type safety bites me right in the ass!

Premise: I'm doing some J2EE boilerplate coding to get our authentication system working again. To get started, here's the API of interest. public class HTTPSession { public void setAttribute(String name, Object value); public Object getAttribute(String name); ..... } public class UsernamePasswordHandler { public UsernamePasswordHandler(String username, char[] password); public UsernamePasswordHandler(String username,…

Get XOM

XOM has the best API ever. In my app we churn business objects into XHTML then XSL:FO and finally PDF. XOM makes it super easy to build the XHTML tree. And if I play my cards right, I might be able to turn that XHTML into FO without serializing…

JButton borders

With Swing's Windows look & feel, you can remove the border from a JButton by replacing it with null: JButton myButton = ... myButton.setBorder(null)`</pre> Unfortunately this code has **no effect** in the Aqua look & feel! Therefore whenever you remove the border from a JButton, replace it…

I pity the fool who don't report with FO

I needed a reporting system to replace JFreeReport. Although it's a decent project I found it very cumbersome to create reports with dynamic columns. My solution is to create the report in XHTML, and use FO to convert that into PDF. It's very easy to code my document's tables using…

Java ID3 MP3? Good luck!

Today we attempted to parse some MP3 files with Java and we ran into some frustration. We're using the latest iTunes to do ripping and require compatibility with the latest and greatest of ID3v2. Here's what I found: [de.ueberdosis.mp3info](http://www.ueberdosis.de/java/id3.html) The API…

JBoss 4 and JAAS

I've just wasted two days trying to figure out why my J2EE app's login wasn't working. Here's the EJB code: /** * Log in as this user. * * @ejb.interface-method * view-type="local" * @ejb.transaction * type="Mandatory" */ public void tryLogin() throws LoginException { logger.info("Logging in to " + LOGIN_…

Why SWT, Why?

So in SWT there is this thing called a KeyListener. One might expect something called a KeyListener to listen to events on keys. Well, you'd be right, unless you consider the CTRL or the SHIFT keys to be keys. According to the KeyListener, they are just state modifiers, and as…

An idea: auto-unboxing

Primitive Collections I'm aware of at least two libraries for Java that provide collections for each of the six primitive types. So instead of storing Integer Objects in an ArrayList, you get to store int primitives in an IntArrayList. This saves RAM and it speeds things up. It's a clever…

Thoughts on Predicates and/or Matchers

Rob is working on making filter development easier. Currently whenever a user wants to do some custom filtering, they need to extend our AbstractFilterList and implement its filterMatches(Object) method. This gets the job done but there's some problems: Discourages code reuse from the filterMatches() method Reinventing the wheel: many…

Notes on variable-height rows in a JTable

Recently Sun hosted a developer web chat, Getting High Performance from Your Desktop Client. I decided to ask about a problem I faced a few months ago: performance of JTables with variable-height rows. The Premise To track the heights of each row, JTable uses a SizeSequence. This class stores the…

Simple mail trick for good or evil

My mail client (Mail.app) allows me to configure which email headers get displayed. I set it up to display some extra headers for my own novelty... X-Mailer: display the Mail client program used to craft a given email. This is mostly for my own curiosity. If somebody is using…

32 bit file sizes in Apache HTTPD

Today I backed up some files from my Powerbook to a DVD image. Once I created the DVD image I was going to transfer it to my PC which is the home of my burner. How shall I transfer the file? Via SMB? Nope. I've had very little success with…

JComboBox and equals()

For some reason, my PrinterData object has a broken equals() method. This means that if you call somePrinter.equals(somePrinter), the result is false. Yuck! How did I discover this simple bug? When I put the PrinterData object in a JComboBox, the JComboBox wouldn't let me select anything! Weird.…

An obvious extension to JScrollPane

The JTable is a large abuser of the JScrollPane. Out-of-the-box, JTable doesn't have a header. Only when you add it to a JScrollPane does it get its header, which gets stuffed into the JScrollPane's top track so that it is not scrolled. This is a hack. But it works. When…

A FilterList for sale

Here at O'Dell Engineering, we are continuously looking to find a way to recoup the costs of developing Glazed Lists. We've had two more ideas, both of which I think are decent: Sell the MBean that publishes NetworkLists from within JBoss. Sell a FilterList that works like TextFilterList, but with…

Bind a single time to the same port in Mac OS X

I think I've resolved a problem I came across earlier: I could bind to the same port multiple times using NIO on Mac OS X. A kind soul named Timothy Wall has helped me to work-around the problem. Just call setSoReuseAddress(false) on the channel's socket before binding: ServerSocketChannel channel…

The inconsistencies of the SWT.FILL style

It seems like there's no shortage of unusual behaviours to be found in SWT. The most recent one that I've come across is the behaviour associated with the SWT.FILL style. Consider the layout found in the GlazedLists demo. Laying out the interface in a single GridLayout puts two Tables…

Stupid Bash Tricks: Find a file in a pile of jars

My latest code depends on ServiceMBeanSupport.class from JBoss. The problem is that JBoss is composed of dozens of .jar files and I'm not sure which one contains the file I'm interested in. Tools find this command will list all the files that meet the specified metadata. It can also…

PLAF Detection Workaround for Ocean Metal and Windows XP

Currently, Swing has a couple of bugs which hinder PLAF detection on the client. In particular, Windows and Metal suffer from ambiguity in their UIManagers. In GlazedLists it's important that we inspect the PLAF precisely so that the pixel-perfect sort arrow icons that Jesse made are chosen correctly. Jesse wrote…

SWT vs My Sanity: Round 2

I'll try to keep my rants on SWT to a minimum, but I feel the need to provide information to others who run head first into the brick wall that is SWT. I remember reading a comparison of Swing and SWT some time ago and it clicked into my mind…

My private interfaces design pattern

So I found myself writing some code that seemed like a GoF design pattern. I'm not so sure that it is, but if it were, here's its criteria... Name: Private Interfaces Intent: Implement methods in a class without exposing them in the public API. Motivation: Hiding methods prevents them from…

Bind several times to the same port in Mac OS X

My PowerBook lets me bind to the same port twice using NIO. The following code throws an IOException under Windows and Linux, but not under Mac OS X: public void bindTwice(int port) throws IOException { InetSocketAddress listenAddress = new InetSocketAddress(port); ServerSocketChannel firstChannel = ServerSocketChannel.open(); ServerSocket firstSocket = firstChannel.socket(); firstSocket.bind(…

Oh SWT, how I loathe thee. Let me count the ways.

Some reasons why SWT frustrates me in no particular order: A column title in a table header has the same justification as the contents of the column. Common style constants have common (and therefore ridiculously vague) descriptions in the documentation. Next to no effort was put in to provide more…

How many bytes to the centre of the tootsie pop?

Today I ran into an unexpected problem while dealing with InputStreams and OutputStreams... Pop-Quiz How many times is "World O Hell" printed when the following code is executed? for(byte i = -128; i &lt;= 127; i++) { System.out.println("World O Hell"); } < 256 times…

Dump a Java Stack Trace

Sometimes I write broken code. Sometimes my test cases never complete. For this, there is a simple solution. Type CTRL+BACKSLASH into the Java process. The result is a full stack trace of all my JVM's threads. It's a great way to debug deadlocks.…

Apache MyFaces

My current project at work uses JavaServer Faces extensively. Although the current implementation feels like a version 1.0, it's quie a kick-ass framework. Today I found out that a small component called "NewspaperTable" that I have built has made its way into the MyFaces open source JSF…

Docbook and a Glazed Lists Profit Model

I think that Glazed Lists has to be open source for the project to be successful. Currently the project progresses because of the charity of myself, Kevin Maltby, James Lemieux, and O'Dell Engineering Ltd. Although these contributions are voluntary, I think that we need a profit strategy for the project.…

Lead, Anchor and a new ListSelectionModel bug

Today I discovered a new bug in Glazed Lists' EventSelectionModel. That class implements ListSelectionModel, which a JTable uses to manage the current selection. One of these duties is to manage the lead and anchor indices, which are used for dragging a selection with the mouse. Where the mouse started the…

A super() Java Language Hack

I'm creating an EventList called PopularityList that will sort elements by the number of times they occur in the source EventList. I'm extending TransformedList, which has a single protected constructor with the signature: protected TransformedList(EventList source); To implement PopularityList: First I create a UniqueList of the source EventList's elements.…

One Page Whitepaper

I've created a really quick PDF that gives a fast overview of how sorting is implemented in Glazed Lists. I needed to write such a paper for some accounting stuff at work, but it's fun to post online. The only problem is that now JDNC and everyone else can learn…

POI, hyperlinks, and 2^7

As I mentioned earlier, I am using Jakarta POI to create Excel files. Earlier I warned: don't use space characters (or commas or pretty much anything else) limit sheet names to 31 characters Well today I discovered another unpleasant limitation. The link label must be 127 characters or fewer. If…

IOException "The handle is invalid"

The pure Java version of our program was working flawlessly. The GCJ-compiled Windows binary was not. It was throwing an IOException, "The handle is invalid". This is caused because InputStream.close() was being called multiple times. By removing a close() call, everything now works correctly. This raises an…

Filter Faster

The filter classes in Glazed Lists have received a shitload of attention lately. First, James Lemieux implemented Boyer-Moore in our TextFilterList class. His efforts led to a 20-50% performance boost. James is currently working on refactoring the TextFilterList and AbstractFilterList classes which may lead to further performance increases. Now today…

SWT Frustration of the day: Constants

The SWT GridData class has 25 public static final int constants, including the following: `BEGINNING` `CENTER` `END` `HORIZONTAL_ALIGN_BEGINNING` `HORIZONTAL_ALIGN_CENTER` `HORIZONTAL_ALIGN_END` `VERTICAL_ALIGN_BEGINNING` `VERTICAL_ALIGN_CENTER` `VERTICAL_ALIGN_END` Pop-Quiz: GridData also has a constructor: public GridData(int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean…

UniqueList, Bag, and Sorting 2x

I am writing a user interface for data-entry. Because data-entry sucks I am trying to make this UI as usable as possible. This includes accelerator values for each field. For example, a field to enter a car name will include buttons for each of the most popular values for that…

POI and Hyperlinks

I have a program that generates an Excel file that can contain hundreds of sheets. To make this more manageable, the first sheet is an 'index' sheet that summarizes the sheets to follow. Each row in this index is hyperlinked to the a sheet that provides further detail. Here's some…

JavaBeans in Comparators

Data objects are the new orange! So I am continuously coding data objects and I find myself writing a lot of repetitive comparison code: ` public int compareTo(Object other) { if(other == null) return -1; Car otherCar = (Car)other; if(myColor == null && otherCar.getColor() != null) return -1; if(myColor.…

My Bizarre XML Alternative

Originally, the Glazed Lists demo app would parse a file called "issues.xml" each time it was run. I got "issues.xml" by exporting my Issuezilla database from java.net. This worked okay, but the exported XML included everything in the database including attachments. Of course…

Event Listeners and dependencies

There was a recent bug in Glazed Lists that was difficult to plan for. Consider this: "S", a source list "F1", a filtered transformation of "S" "F2", a filtered transformation of "S" "FF", a filtered transformation of "…

IBM developerWorks "TableModel Free" looks too familiar

From ClientJava.com I found a link to TableModel Free, a framework that allows you to "Free yourself from the burden of the TableModel". TableModel Free reminds me of Glazed Lists: Decorators are used to make the Java Collections observable. It includes a TableModel that observes such a…

SQL "is equal to", <>, and NULL

Time for a complaint about how SQL deals with NULLs. CREATE TABLE colas ( brand VARCHAR(32) ); INSERT INTO colas ( 'Pepsi' ); INSERT INTO colas VALUES ( 'Coke' ); SELECT * FROM colas WHERE brand <> NULL; The above select statement does not return { 'Pepsi', 'Coke' }. Instead, it returns 0 rows. This is because I should…

Checked and unchecked exceptions in EJBs

EJBs are good. But here's something lame: Throwing an unchecked exception (ie. RuntimeException) causes the current transaction to be rolled back. Throwing a checked exception (ie. a declared exception) does not roll back the current transaction. I never throw any exception from my code that does not require a roll…

Shiny! Drawing XP icons

Today I tried for a few hours to get Xandros to burn some DVDs on my new burner. It was grumpy so after two DVD-coasters I threw in the towel and installed Windows XP. It's a decent alternative to Linux but it has a crappy shell and its SMB client…

Hello, World

I've been thinking of starting a tech-focused weblog for a long time now. Well, consider this "Hello. World". My intention is to talk about Glazed Lists stuff mostly here, and perhaps some other Java stuff. Personal rants will continue to be on swank.ca.…