Approach

Outline:

Want to focus on good design and not so much the interface. I hope to have an applet/application which is extensible and has some reusable classes.
 
Note: I have saved versions of my code along the way to the final product. Besides the many other good uses of this, it could be used to verify that what I have coded is my own work and that I didn't start with someone else's code.
I have put all my classes into packages using a bogus company name of enlighten. To start my application use:
    java enlighten.apps.GraphAnimator.GraphAnimator
This structure made it easier to jar up all the required .class files.

Steps:

 
Stage Description
Preliminaries
  • First I started by researching on the Net to find any info on the algorithm or any Java code I might be able to use and/or peruse. Any stuff I download from the Net is in the "net" directory.
  • The best thing I found was a description of the Dijkstra's algorithm (and others), along with a description of how to implement a graph. This may not be in the "net" directory. I have a hard copy which I will include with my assignment.
  • I also found an applet which would probably be worth full marks in this assignment. It looked very good. However I couldn't understand how it got the algorithm to work. It was not very Object Oriented. It claimed to be extensible in that other algorithms could easily be incorporated. I really doubt that claim. However, it did have some amazing looking stuff to draw the edges (particularly the arrows) which I thought I might use. It was copyrighted so I'm not sure that I can even do that. I will note further steps and in my code if I reuse any outside code. I found some Java standards on the Net and tailored them to suit me (I have included the standards page in "net" directory). I will hopefully produce a reasonable standards page of my own later (I have produced a ClassTemplate.java).
v0.01
  • I decide to go it alone, at least initially.  I produce a set of classes which implement the graph as an adjacency list and also write a working version of the shortest path algorithm.
  • Version saved in GraphAnimator-v0.01 directory.
v0.02
  • Next I got excited about an idea to be able to edit the graph with unlimited undo/redo. I created and tested a bunch of classes: EditCommand, GraphCommand, AddNodeCommand, CommandHistory, CommandHistoryTest. These were not at all integrated yet. 
  • Added classes to display the graph. No editing at this stage. It displays one of 4 selectable example graphs. I referred to the GraphAlgorithm code to help me with the arrows. I also borrowed Geometry and Calculus II 2nd Ed. from my flatmate to help me understand what I was doing. It was full of relevant stuff and much thinner than I remembered! There must be a precision error in GraphAlgorithm code because I too experienced it with my arrows. It caused arrowheads to be drawn slightly off the line. I have fixed this by using doubles when calculating the arrow points. The particular error was caused by converting a double to and integer and then using the integer in another calculation with a double.
  • To produce this version I added to the classes I already had (Node, Edge, DirectedGraph). I realised later that I could have probably extended them and leave the original non visual versions as they were. I will attempt to pull them apart later, if time permits.
  • Also note that currently edges are always calculated before they are drawn. This is because an edge in the opposite direction causes it to be drawn differently. I'm not sure whether to go the "always calculate before redraw" or "calculate only when necessary" approach.
  • I have begun to modify the Java Standards that I found on the net. This is in the docs directory called "JavaStyleGuide.html".
  • Version saved in GraphAnimator-v0.02 directory.
v0.03
  • Created a package called enlighten.visual containing interfaces and classes such as Drawable, Dragable, VisualCanvas.
  • Modified Node to implement the Dragable interface
  • Modified Edge to implement the Drawable interface
  • Added plenty of event handling code to GraphCanvas. Graphs can now be drawn from scratch. Node can be inserted and deleted. Edges can be drawn.
  • Oustanding issues: Still can't edit nodes and edges. Can't delete edges. Can't get context menus to work correctly since isPopupTrigger() always seems to return false.
v0.04
  • Took a quick look at Swing in an attempt to use it for Dialog based input. Decided against it and coded my own based on one from Java 1.1 in 21 days. Used the dialog to input node labels and edge weights.
  • Enhanced the calculations for the positioning of the edge weights. Increased weight font size.
  • Unfortunately to code Edges with hot spots for deleting, editing etc. I have made Edge implement Dragable even though it doesn't drag. Also, the event handling is looking awfully non OO. Might have to let hot spots work for all Drawable objects in a VisualCanvas. And also possibly provide event handling functions in Drawable (e.g. edit, delete, move). These would then be called by VisualCanvas. Combining Drawable and Dragable would then seem like the right thing to do (back to the concept of just one Visual interface). I could have functions to determine dragability. I was just trying to keep the interface small.
  • Having problems when I define more than one context menu. Having one menu for Nodes is fine. Adding another for edges then causes the action events of the Edge menu to be delayed until an event is sent from the node menu. Weird! All events are accessible in other ways, so it doesn't cripple my code.
v0.05
  • This version allow the SPF algorithm to be run. I have created a run button and a text area for the algorithms output. Changes colors of the nodes and edges as the algorithm progresses.
  • Still doesn't display paths visually.
v0.06
  • Wrote new class AlgorithmInfo which allows information to be attached to nodes by algorithms that are running. More importantly this class allows the algorithm to return a string which is displayed in the node while the algorithm is running.
  • ShortestPathAlgorithm updated to use AlgorithmInfo. Now displays path lengths in nodes while running.
  • Moved node labels out of the node itself, to the top and slightly left.
Final Release
  • Fixed context menus for nodes and edges (my fault). Added 'Set as start' menu item for node's context menu. This problem was due to a copy/paste/edit bug. I had added action listeners to the wrong menu items.
  • Used java.text.DecimalFormat to limit the number of digits after the decimal point for edge weights and path weights (as displayed in the graph).
  • Highlight the minimum path using color (pink!).
  • Fixed bug with keeping the nodes inside the canvas while dragging.
  • Added space to the bottom of the input dialog box so that the buttons aren't hidden by the warning signs (looks odd running as application now, though).
  • Tested from home under Win95 using:
    • java (jdk1.1.6) - using GraphAnimator as an application
    • Netscape 4.04 with 1.1 patch
    • Explorer 4.0
    • Appletviewer (jdk1.1.6)
  • Tested home page version using:
    • Netscape 4.04/w1.1 (Win95)
    • Explorer 4.0 (Win95)

Tools: