Thurs., Apr. 20

pa05 Discussion

DomEcho01.java has the "boilerplate" code that gets the DOM parser to read the XML file and create the DOM tree.

The tree ends up available via Document document.  Note that a Document IS-A Node, so the Node API that we looked at last time is relevant.

The code in DomEcho01.java that is called from main is just there to show you that there is data in the DOM tree.  It is not directly useful for pa05.

So replace it with the recursive traversal we discussed last time.

That handles the first part, XMLDisplay.

The second part, XMLBrowser, mimics what a browser such as Intenet Explorer or Firefox does when it displays an XML file.

Try it out.  Click on +s and -s and see the effect.

Future: Get examples from old classnotes Nov 18

We went over some cases, showing that the expansion status of various elements is "sticky", that is, even when you can't see part of the tree, the expansion status is kept, so that when it reappears, it reappears partially collapsed in some cases.

Thus we need to keep information on the expansion status and lineNo of non-leaf elements.  How to do this?

Set up Decoration class to hold the needed info--expanded true/false and line#

How to put a Decoration on each Node?

Two ways to go.
1.  As in the assignment sheet, set up a Map from a Node's Object.hashCode() to Decoration object
2.  Use Node.get/setUserData to attach a Decoration to each Node.

Class structure
XMLDocument.java:  has methods display() and toggleExpansion(lineNo)
  wraps a Document object, so gets this at constructor time.
   has nested class Decoration
   has DecorationMap if doing method 1. above
   
Also, when we get a line number to toggle expansion for, we need to be able to fine the right Node.  Two ways to go here too:
1.  Use binary search down the tree, using the fact that the line numbers increase over the sequence of children of any node.
2.  Add another Map to XMLDocument, that maps from line number to Node.

Then we started Binary Trees.