martes, septiembre 24, 2013

jGnash is a personal financial software, available as Free Libre Open Source Software (FLOSS). I've been using it since some years, and i can say that is a great software. It has many functionalities, PDF reports and charts, to register and control your incomes and expenses. It just lack of some analysis reports, so i decided to build my own.

It's possible to create plug-ins for jGnash. So you can add a new functionality or a new report, without recompile the whole software. There's a folder in jGnash installation directory called "plugins", in this folder you can add a JAR file containing the new plug-in and next time you start jGnash, it will load your plug-in.

Requirements to build a new plug-in

For build a new plug-in you will need Java programing knowledge, and some specifics thing depending on the kind of functionalities that you are trying to extend. For building new graph charts or reports, I will suggest experience related to: Java Swing, JFreeChart, DynamicJasper and JasperReports. There is not good documentation about packages and source code of jGnash, but you can download the source code and will find is not hard to read, also you will find help on email lists.

According to jGnash help menu, these are the external libraries they use, so could be good also know a little bit about them: args4j, db4o, JasperReports, DynamicJasper, JFreeChart, JGoodies Animation, JGoodies Forms, JGoodies Looks, Apache MINA, XStream and SwingX.

I like Eclipse IDE, so I will use it, but any Java IDE should be good.

Of course, you must have installed jGnash, to link the jars files to your new plugin project.

Architecture

jGnash provides a plug-in system that is easy to understand. The jgnash2.jar provides a interface called: jgnash.plugin.Plugin and a abstract class called: jgnash.plugin.AbstractEnabledAction, to create a new plugin, inside the new plugin jar, just implement the Plugin interface and extend the AbstractEnabledAction.

Also it will be needed to write a couple of lines inside the jar MANIFEST file.

Steps to create a basic plugin

1- Start a new Java Project, this is a normal Java project in Eclipse IDE.

The line menuItem.putClientProperty(Plugin.PRECEDINGMENUIDREF, "new-command"); will tell to jGnash where to add the new menuItem, the preceding code, indicate before New Command menuItem. Other places you can choose are listed in the source code of jGnash, check this file:

It's important to set the "NAME" and "Action.SHORT_DESCRIPTION" values, they will be shown as the title and tool tip text of the menuItem.

The actionPerformed method will be executed when the menuItem is clicked by the user, in this example will show a simple dialog window saying "Hello World".

6- Creating the jar file. In Eclipse, right click over your project, select Export, and then Jar File.

After that, follow the instructions, and take care when "Jar Manifest Specification" windows appear, select the option: "Use existing manifest from workspace", and choose the "MANIFEST.MF" file that we have created before.

7- Copy the generated jar file inside "plugins" folder of jGnash, run jGnash and you will see the message "Hello World" when you click the new menu "Title" inside "File" menu.

Thanks to jGnash developers for this great software. My hope is that lots of jGnash plug-ins come alive to make it a better software for all.

Términos y Condiciones - Terms and Conditions

El contenido de este blog no ofrece ninguna garantía. Usted puede utilizar este contenido bajo los términos de la la licencia: WTFPL Versión 2, publicada por Sam Hocevar. Vea: http://sam.zoy.org/wtfpl/COPYING para mayores detalles.
The content in this blog comes without any warranty. You can use this content under the terms of the License WTFPL Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details.