Dissection of Joeffice: Open Source Office Suite in JavaJuly 11, 2023
Let's explore libraries and framework used to write an open source office suite in Java.
10 years ago, I challenged myself to write an office suite in Java in 30 days. This is how the first version of Joeffice was born. This created quite some buzz, including articles on Slashdot, Ars Technica and PC World.
Last month I released a second update. Let's explore how I did this. By levering Java libraries, I was able to create such a complex piece of software very quickly.
The NetBeans Platform
The NetBeans Platform is a desktop application framework. You can see it as shopping for the parts (modules) that you'd like to have from the NetBeans IDE.
In the case of Joeffice, I shopped for many things: the core API and UI, the start-up screen, the look and feels including the dark themes, the file system, the search and progress API, the settings, print and more.
One of the most visible benefits of the platform is the windows management system. It allows you to have multiple documents opened in the same application, either with a tab system or docked next to each others.
I remember when tabs were introduced in Quattro Pro 5 spreadsheet software or Opera browser, quickly the competition followed up and now you can't have a browser or spreadsheet software without tabs.
With the NetBeans Platform, I had this feature directly out of the box for free, so people can have 20, 50 documents opened and still be able to manage the windows.
Another part where the NetBeans Platform will save you a lot of time is for creating installers for the different platforms Windows, Mac OS and Linux.
There is online documentation and several books to learn how to use it.
Depending of the kind of document you want to open, Apache POI has a more or less complete API to get the details. The most complete is to read Excel files. It also includes an interface API with 2 implementations, one for xls files, the old Excel format and one for xlsx format, the current Excel format. In Joeffice, I also implemented the interface to be able to parse CSV documents.
A big part of Joeffice is to translate the information from the document to its visual representation. If you use Apache POI at your company, you could use Joeffice as a playground to understand and play with the Apache POI library.
Swing is a Java graphical user interface included in Java. Instead of relying on native components, like the AWT API is, each component is drawn in Java using the Java 2D API. The main advantages are consistency between the platforms, the possibility to make the component skinnable, also called look and feel, and it's quite easy to define or override new components.
Joeffice makes heavy use of 2 Swing components:
- JTextPane: This component is used to represent rich text and is the base to show word and powerpoint documents.
- JTable: This component is used to represent a table and is the base to show spreadsheets and database data.
As previously mentioned, it's easy to override or create swing components, for example Joeffice is using the SwingX library that contains extra components and the ETable component from the NetBeans Platform.
In the latest release of Joeffice, I've made it easier to reuse the Excel table component without relying on the NetBeans Platform. From it, I've created an Excel viewer applet and the Sheet Viewer application.
Here is a quick overview of some other libraries used in Joeffice:
- H2 Database: An open source pure Java database. It also includes a CSV parser.
- Apache Batik SVG: An API to draw .svg files. It is also part of Apache POI dependencies.
- JUniversalCharDet: Help to detect character encoding of text files. Used to parse CSV text file.
In this article, we've seen on how by combining several API's we can create a new software.
Joeffice is under the Apache license, so if you're interested to learn any of the previously named libraries, you can download the code from GitHub and play with the libraries.