SerializationApp (version 1.1)

 

Introduction

SerializationApp demonstrates serialization of an advanced data construct, AbstractDataModel. Use of an ADM (AbstractDataModel) demonstrates a MVC (Model-View-Controller) scheme in Java Swing: The ADM represents the "model", the JTable represents the "view", and the GUI panels and buttons associated with the JTable are the controller. Unlike version 1 of this lab, the ADM is serialized (not just the table data), allowing for greater flexiblity of manipulating the data and it's associated behavior.

My first version of this lab (version 1.0 here) populated the JTable by serializing the data within the ADM (as a vector of rows). This worked well, but after examining other serialization examples, I decided to rework and enhance version 1.0. In this second versio, I now serialized the table model to allow for greater flexiblity of manipulating the table. Additionally, I took the previous attempt much further by abstracting the data represented in the ADM, requiring these data classes to implement serialization as well. My JTable also permits real editing of the data, with custom cell editing, rendering, and row addition/removal. Some of this functionality was taken from Swing example on the Sun Java tutorials. Using JFileChooser, this data can be persisted out to a file and later restored from a file to load a table. As it stands, simply serializing the table model does not by itself introduce added functionality to a JTable, but it will allow for greater enhancements to manipulating the data later on (see Complexity below).

Running This Lab

SerializationApp is a self-executable JAR file. Simply download Lab1_1.jar (or Lab1_1.zip and rename it to *.jar) to your local directory and double-click it in your GUI environment. It can also be executed from the command line using : "java -jar lab1_1.jar". that can be executedBegin by downloading the Lab1.jar file to a convenient local directory and unjarring it with jar xvf Lab1.jar . Change to the classes subdirectory and run the application with java ExpenseRecord . The application will come up displaying a default set of data. You can experiment with adding and removing rows, editing the data fields, and saving the results to a file with Save menu choice. By selecting Open from the menu, you can load a table with previously saved data.

 

Lab Complexity

As illustrated in version 1.0, simple serialization is a straight-forward matter (simply add the uses serialization clause). But in version 1.1, serialialization of the table model used (AbstractDataModel), required that I implement the ReadExternal and WriteExternal methods to describe the serialization mechanism. In the next release of this lab (version 1.2), I will allow multiple undo and redo steps of table editing(these buttons are currently not functional). Using a stack, each undo will reverse the last action taken on the table (a row added, a row deleted, or a row edited). A redo requires it own stack since a redo reverses the last undo that was executed. Implementing both functions, therefore, will require two stacks, and since they will be persisted with the rest of the table model, multiple undo and redo steps would be possible even after the table has already been persisted out to a file.

 

Deliverables