/*
 * EditSomeXML is a graphical XML editor
 * 
 * Copyright (C) 2014  David Jackson
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package editor;

import utility.Observable;
import utility.Observer;
import xml.Element;

import java.util.ArrayList;

/**
 * The ElementTreeData class is used to encapsulate a tree of Elements
 */
public class ElementTreeData implements Observable {
    private Element root;
    private ArrayList<Observer> observers;

    public ElementTreeData() {
        root = null;
        observers = new ArrayList<Observer>();
    }

    public ElementTreeData(Element elem) {
        root = elem;
        observers = new ArrayList<Observer>();
    }

    public Element newRoot() {
        root = new Element();
        return root;
    }

    public Element setRoot(Element elem) {
        root = elem;
        for (Observer observer : observers) {
            root.registerObserver(observer);
        }
        return root;
    }

    public Element getRoot() {
        return root;
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
        root.registerObserver(observer);
    }

    @Override
    public void unregisterObserver(Observer observer) {
        observers.remove(observer);
        root.unregisterObserver(observer);
    }

    @Override
    public void notifyObservers(Object obj) {
        root.notifyObservers(null);
    }
}

@@ -932,16 +932,151 @@
 Elements
+. It%0A * contains the tree and observers of the tree. Primarily this class is used%0A * to enable the ElementTreeModel to access the tree.
 %0A */%0Apub
@@ -1195,16 +1195,94 @@
 rvers;%0A%0A
+    /**%0A     * Initialize the tree data with no root and no observers%0A     */%0A
     publ
@@ -1316,74 +1316,153 @@
     
-root = 
+this(
 null
+)
 ;%0A    
+%7D%0A%0A
     
-observers = new ArrayList%3CObserver%3E();%0A    %7D%0A
+/**%0A     * Initialize the tree data with a particular root element%0A     * @param elem The root element of the tree%0A     */
 %0A   
@@ -1584,92 +1584,356 @@
     
-public Element newRoot() %7B%0A        root = new Element();%0A        return root;%0A    %7D%0A
+/**%0A     * Generate a new root element for the tree%0A     * @return the new root element%0A     */%0A    public Element newRoot() %7B%0A        root = new Element();%0A        return root;%0A    %7D%0A%0A    /**%0A     * Set the root of the tree to a particular element%0A     * @param elem the root element of the tree%0A     * @return the root element of the tree%0A     */
 %0A   
@@ -2118,24 +2118,124 @@
 oot;%0A    %7D%0A%0A
+    /**%0A     * Get the root element of the tree%0A     * @return the root element of the tree%0A     */%0A
     public E
@@ -2273,32 +2273,79 @@
 rn root;%0A    %7D%0A%0A
+    /**%0A     * @see utility.Observable%0A     */%0A
     @Override%0A  
@@ -2469,32 +2469,79 @@
 server);%0A    %7D%0A%0A
+    /**%0A     * @see utility.Observable%0A     */%0A
     @Override%0A  
@@ -2676,24 +2676,71 @@
 er);%0A    %7D%0A%0A
+    /**%0A     * @see utility.Observable%0A     */%0A
     @Overrid
@@ -2816,20 +2816,19 @@
 servers(
-null
+obj
 );%0A    %7D

Add documentation to ElementTreeData class