www.pudn.com > DomView.zip > DomTreeModel.java


/******************************************************************** 
Domview 1.0 displays contents of an XML DOM object 
Copyright (C) 1999  The Bean Factory, LLC. 
 
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 2 
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, write to the Free Software 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 
Author: Sun Koh, The Bean Factory, LLC. 
*******************************************************************/ 
import java.awt.*;                  //AWT classes 
import java.awt.event.*;            //AWT event classes 
import java.util.*;                 //Vectors, etc 
import java.io.*;                   //Serializable, etc 
import java.net.*;                  //Network classes  
import javax.swing.*;               //Swing classes 
import javax.swing.event.*;         //Swing events 
import javax.swing.table.*;         //JTable models 
import javax.swing.tree.*;          //JTree models 
import javax.swing.border.*;        //JComponent Borders 
 
import org.w3c.dom.*; 
 
/******************************************************************** 
 DomTreeModel encapsulates a XML Document object  
 
 
 @version      : 1.0 
 @author       : Sun Koh 
 
********************************************************************/ 
public class DomTreeModel 
extends java.lang.Object 
implements TreeModel { 
 
// 
// Data Members 
// 
    protected Document doc; 
    protected java.util.List listener = new ArrayList(); 
 
 
// 
// Methods 
// 
/** 
 Default Constructor  
 
 @param 
 */ 
    public DomTreeModel(Document doc){ 
        this.doc = doc; 
    } 
 
     
     
    // 
    // Implement Tree model 
    // 
    public Object getRoot(){ 
        return doc; 
        //return doc.getDocumentElement(); 
    } 
 
    public Object getChild(Object p, int i){ 
        NodeList nl = ((Node)p).getChildNodes(); 
        return nl.item(i); 
    } 
 
    public int getChildCount(Object p){ 
 
        NodeList nl = ((Node)p).getChildNodes(); 
        return nl.getLength(); 
 
    } 
 
    public int getIndexOfChild(Object p, Object c){ 
        NodeList nl = ((Node)p).getChildNodes(); 
        int size = nl.getLength(); 
        int i; 
        for(i = 0; i