I’ve been given the task to implement a new end-user functionality into a Java/Swing application. The task to implement is relatively easy and straightforward. What is cumbersome is the existing app to be modified.
It comprises dozens of classes which often break the 2000 lines barrer and sometimes reach 10000 lines.
Documentation is non existent and it is unfeasible to read all the source code to get the big picture of it.
The app itself is basically a GUI tool to draw diagrams (e.g. flowcharts) and is open-source (I can post the link to the source code if it helps).
So far I’ve managed to import the source code into an Eclipse project and use the SwingExplorer plugin to identify some of the GUI components.
The most ‘interesting’ part of the app is the canvas onto which the diagram is drawn. It is implemented as a single class (about 9700 lines long) that inherits from JComponent.
The parts of the displayed diagram can’t be selected in SwingExplorer: the whole canvas is only identified as a single instance of the aforementioned class.
I hence guess that this huge single class is taking care of all the user interactions and AWT drawing operations for the diagram and returning just some kind of image buffer to display (but this is a huge guess).
My modification involves doing computation on the diagram as it is being drawn on the canvas. Therefore it is going to be a new class which will receive and process events broadcast during the creation of specific elements of the diagram, and then do some computation on them.
My main problem is: how to debug the event flow? How can I follow the flow of execution when drawing a diagram and see which events are generated, processed and also get an idea of where in memory the objects being drawn reside?
I know this question might seem too generic, but I’m really clueless and looking for a starting point.
Thanks in advance only for taking the time to read through 😉
Regards,
Marco
In NetBeans, I use
File > New Project > Java Project with Existing Sourcesto allow easy navigation. Most IDEs have a similar feature.Use
Run > Generate Javadoc; even without comments, theOverview,Index,UseandTreelinks may be useful.Set breakpoints in the debugger and use
Window > Debugging > Call Stackto answer question like, “How did I get here.Run the code in the integrated
Profile > Profile Projectmode to see principle execution threads.