Reverse Engineering my own Brain

A few days later…

It is indeed a tribute to the amount of time I spent on flowing and commenting this code, that I have been able to step back up to the project so quickly. Sure there are lots of little nagging snags to overcome but I am following my previous cognitive pattern quite nicely. That is, in everything but one key area.

You see, Netbeans Form Designer does something really dumb. It creates code of the following ilk:

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(kongzi.Kongzi.class).getContext().getActionMap(ExportDialog.class, this);
exportButton.setAction(actionMap.get("exportSelected")); // NOI18N
exportButton.setName("exportButton"); // NOI18N

oohh… but you already know where this is going. This is stupid beyond all belief. I cannot possibly imagine what imperative posessed the minds of the people who made form designer to do this. This is simply, never a default desire of the programmer. It’s overcomplexity to the extreme.

The problem is that when yguard obfuscates my code, it doesn’t know how to rename the “exportSelected” string.

Now here’s the thing. A year and a half ago, I actually solved this problem. I tripped over the solution one day while reading the netbeans help files. I actually figured how to make it set the event handlers without using reflection. It was literally a one in a million chance. But all I can remember about the incident was that I thought “No one would ever have been able to find this, it’s buried in the help files” and “thank god I figured this out, now I can use form designer AND obfuscate my code!”

Ok so now, nearly two years later, what the heck was I thinking?

I have been all over – and I mean it – all over the help files.

I have looked EVERYWHERE in configuration, navigator and inspector. Nothing relevant. I’ve turned OFF automatic resource management (a good thing I think) but that still didn’t solve the problem.

The best solution I can come up with is to define, say, a jButton by usuing events–>actionPerformed versus “Set Action” which delves into the whole actionMap(x) thing.

The scary thing is, I don’t know if this is the solution I figured out last time, or not. Because I was very happy with the solution last time. I’m worried. I’m going to convert everything to use actionPerformed versus @action, but you know, it’s just scary, because the solution I had last time was so elegant, and now I don’t really remember what I did.

I wish I didn’t lose my backups.

I made lots of backups but they dissapeared.

I feel sick and sad because I lost my backups.

It was only two weeks of work but it, apparently, was the best two weeks of my entire life.

Advertisements

One Response

  1. Hello, you can change the line code manually outside Netbeans using notepad or other text editing software.
    I know it’s a pain because Netbeans won’t let us edit that generated code.

    Okay, hope this helps.

    Renli responds: Thanks. The way I do it now, is instead of using right click (on a component) then “Set Action”, I use right click (on a component) and “Events” then “ActionPerformed”. This seems to have solved my problem, although I cannot remember if you also need to set internationalization to off, or some sort of resource file flag…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: