![]() |
JSwat ProjectThe Great Refactoring |
What was so wrong with JSwat that brought on this big redesign?
Basically everything. The program was written under the assumption
that there would always be a graphical interface. Thus, many
shortcuts were taken in the design and implementation. In
particular, there was a lot of dependence on a class called
MainWindow
. This was referenced by the
Session
, most of the actions, and even some
commands.
The change was really brought about when a user named Jack suggested to me that JSwat should support a console-only mode. This intrigued me since I fancied the notion that JSwat was so well designed that this sort of feature should be easy. Hah! It took three weeks (well, really two) to change all of the classes to support an arbitrary interface. The rest of this page outlines what was done to make this possible.
First, the UIBuilder
class had to be replaced by
something more generalized for building any type of interface.
Second, the MainWindow
references had to be replaced
with references to the new generalized class. The
CommandManager
class had to stop managing its own
interface components, namely the text input field and key press
listener. The Session
had to sever its ties with the
UiBuilder
and MainWindow
classes, as well
as all of the panels.
All of these goals were achieved by the introduction of the
"interface adapter" class. This class would be
responsible for building and managing the entire user interface.
That meant building the main window, menu bar, tool bar, panels,
and handling source view windows. A new interface was written to
provide the basic API for the rest of the program to interact with
the user. This is called the UIAdapter
and it has two
implementations provided with the primary JSwat code.
The GraphicalAdapter
class builds out the usual
graphical interface that all JSwat users are accustomed to. It
makes the main window, menu bar, tool bar, and panels, as well as
handling the source view windows. It provides the mediators for
displaying JSwat messages, taking command input, displaying the
debuggee output, and entering debuggee input.
The ConsoleAdapter
class constructs a very simple
interface. It receives typed input from the user via the
stdin
input stream and displays messages to the
stdout
output stream. It is a purely console-based
interface, much like the well-loved jdb
debugger that
comes with the JDK. There are no panels, no dialogs, no toolbars,
and no source views. JSwat messages and debuggee output are both
printed to the same place as that is the only place to do so.
Sending input to the debuggee is made possible via the
stdin
command, which sends its arguments to the
debuggee's stdin
input stream.
Granted, most people are not going to rush out and use the console mode of JSwat, but it has brought about necessary changes in the program's design. The classes were too tightly-coupled and inflexible for there to be any chance of future expansion. In addition, it has made David Taylor's task of writing a plugin for jEdit much easier. This, I am sure, is something that at least some JSwat users can appreciate. In the future, it will be much easier to write other interfaces to JSwat, allowing for more widespread use and acceptance.