ToolbarBuilder – Use the builder pattern to create toolbars

Recently I discovered  Jeremys uber-ButtonUI’s. He provides UI classes to mimic Mac OS Button looks (and more) including segmented Buttons. The UI’s are nice, but while playing around with, I thought a builder approach would fit to easily create toolbars of buttons and components. Basically the problem is that segmentation configuration depends on Button order ( ;) ), so changing the order of elements within a toolbar now also involves updating the segmentation configuration. Jeremy provides a nice installUI method that helps adding the appropriate button UIs, but I thought this could be improved further and I wanted to play with the builder pattern and find a way to make it extensible without copy/pasting the whole builder.

› Continue reading

Tags: , ,

Monday, September 28th, 2009 Swing No Comments

Bounded beans in IntelliJ IDEA

Well, for some reason I lost my Intellij IDEA configuration. I had a nice live template to create a firePropertyChange statement. This is not as nice as the bound setter plugin for eclipse as it does not create the method but the methods body.

Basically create a new Live Template and set the name to something like “fpc”. The template is

firePropertyChange("$name$", $name$, this.$name$ = $name$);

and the variable definition for $name$ is variableOfType("Object"). Finally set the default value to “name” and you are ready to go. Let the IDE create a setter, remove the body, type fpc and hit tab. This will expand to the firePropertyChange statement and if you are lucky, the variable name is correct ;) Of course, the class has to be some sort of AbstractBean and provide a firePropertyChange

Friday, June 19th, 2009 Other No Comments

Get the current SVN revision number in from Ant

Another minor Problem I struggled with the last couple times I was updating one of my build scripts was resolving the current SVN revision number from within ant. Google points out a few solutions, but most of them require optional SVN tasks or do an exec. Someone (sorry, I would put a link if I could remember) came up with the simple solution of using the stored SVN information from the filesystem. So:

    <loadfile property="svn.revision" srcFile="./.svn/entries">
        <filterchain>
        <headfilter lines="1" skip="3"/>
        <deletecharacters chars="\n"/>
        </filterchain>
   </loadfile>

loads the current revision number into a property called svn.revision. I use this with svn 1.4 and 1.5 repositories and it works just fine.

Tags: ,

Thursday, May 14th, 2009 Other No Comments

Appframework and accelerator keys

Today I re-researched on the topic of assigning accelerator keys to actions depending on the operating system using java appframework. The problem I have is simple. On Mac OS X the “meta” key maps to apples command key. On windows it maps to the “Alt” key. And thats is the beginning of all the trouble. Assume you want to define a “save” action. On Mac the shortcut should be “command-S”, on windows it should be “ctrl-S”. In terms of appframework (or java keystrokes) that means you need:

save.Action.accelerator=meta pressed S

if you are on Mac OS X and

save.Action.accelerator=ctrl pressed S

if you are on Windows. The simple way to to this is

save.Action.accelerator=shortcut S

and “shortcut” will map to the meta key on the mac and to the ctrl key on windows. Remember, this is appframework specific and not a real Keystroke definition. I didn’t find the documentation anywhere ( I am sure it somewhere :) ), but I found that while browsing the source code. It doesn’t solve all the problems related to accelerator/mnemonic/keystrokes on differen paltforms ! But, at least for me, it solved 90% of the problems, because we develope our app in english (so no other locales involved) and “ctrl” is also fine for the linux/unix/solaris platform. I you want to do more or just want to read more about the problem, there is a thread from the appframwork mailing list.

Tags: ,

Tuesday, March 3rd, 2009 Swing No Comments

Set JPA entities at runtime

We use JPA as persistence mechanism for EPoS. The JPA implementation for the next release will be EclipseLink and I was adding that over the weekend. One important thing: I don’t know the entity classes at compile time. That makes it impossible to add the class names to the persistence.xml directly. Somehow we need a way to specify the classes at runtime (well, at least at initialization time, when we boto up the EntityManagerFactory). That is something taht seems to be not part of the JPA spec for Java SE environments ( in Java EE, you can let it search the jar files for entity classes).

Ok, so we need a way to manipulate the content of the persistence.xml at runtime to add the class entries and I found way, hacking into the mechanism that reads the content of the persistence.xml.
Basically, what we do is, we occupy the stream that represents the file and manipulate it at runtime. To do so, we have to extend the initialization process, but, thanks to protected variables used by the EclipseLink team, this works without any manipulation of the EclipseLink source code. We have to extend some classes, to make it work, but thats it. And it turned out that the changes are rather minimal and the hack works straight forward. So, lets jump into the code and get things running. Still, keep in mind, we work on top of internal initialization code ! There is a good chance that this breaks with a new release, although I think it will be straight forward to keep things running…at least as long as the EclipseLink team sticks to protected access modifiers for some of their variables.

› Continue reading

Tags: , ,

Monday, February 9th, 2009 Other 3 Comments

BeansBinding ELProperty as simple template engine

I just read an article about using adding EL support on your projects and I was looking for a nice alternative to Velocity anyways.

I know EL basics from BeansBinding, which I use in most of my UI projects. EL itself looks pretty interesting, but, well, sort of complicated. Even finding the proper jar files seems to be a problem, or at least “another of life’s obscure mysteries” and using EL for a simple search and replace example implies implementing some internals. I was looking for something that I can just use.

Luckily, the first comment mentions the ELProperty class from BeansBinding, and that jar is just a few mouse clicks away, so I thought I give it a try…and…well…it works ;)

› Continue reading

Tags: ,

Thursday, October 30th, 2008 Other 1 Comment

combine multiple jar files and remove signatures

I just came across a situation where I had to join multiple jar files and my own classes into one jar bundle. Ant comes in handy:

<jar destfile="${app.id}-${app.version}.jar"
  index="true"
  filesetmanifest="merge">
  <fileset dir="${classes.dir}"/>
  <zipgroupfileset dir="${lib.dir}" includes="*.jar" />
</jar>

This takes all the files in ${classes.dir}, packs them in a jar and add the content of all the jar files in ${lib.dir}. In this case, we merge multiple manifests, but this can be changed according to the jar task documentation.
› Continue reading

Tags: , ,

Wednesday, October 29th, 2008 Other 2 Comments

Add Copyright to Java Sources

Just found a nice Eclipse plugin that adds license information to a all the files (well, you can select them) in a project. You can specify the license, enter your own, customize the output …. nice !

Just reminds me, we had a java class that did that for QAlign 2 Panta Rei source code distribution.

Yeah, there it is, May 21, 2005 written in Michas old apartment in Barcelona while working on QAlign2.

The QAlign2 crew

The QAlign2 crew

› Continue reading

Tags: ,

Wednesday, October 22nd, 2008 Eclipse, Other No Comments

ANT build.xml template

Just that I have it at one place. This is my ant build.xml template. It assumes a simple project structure:

src/ - all java soources in here
lib/
  devel/ - development libraries
  runtime/ - runtime libraries

If your project follows this struicture, you can get the following tasks out of the box:

Buildfile: build.xml

Main targets:

 clean          Clean
 compile        Compile all source files
 compile-tests  Compile all source files
 dist           Build library and pack jar file
 dist-one       Build library and pack jar file
 doc            Create Javadoc
 html-reports   Creates HTML from test reports
 test           Run JUnit Tests
Default target: dist

You can modify the properties to adapt different names or a different project structure. The script creates a target directory that contains the results.

Compiling and packing should work out of the box, but the test sections expects a junit and ant-junit jars in lib/devel. They can also be placed in one of Ants lib directories.

The build file

Tags:

Wednesday, October 22nd, 2008 Other No Comments

WTF per minute

Yes, that is the right code quality measurement

Tuesday, October 21st, 2008 Other No Comments