Ignore:
Timestamp:
19/08/10 12:43:30 (21 months ago)
Author:
Stephen Rankin
Message:

Added copyright to files. Added some code for filtering bad nodes. ref#236.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/applications/NXconvertpy/src/org/nexusformat/nxvalidate/NXNodeMapper.java

    r1504 r1507  
    1 /* 
    2  * To change this template, choose Tools | Templates 
    3  * and open the template in the editor. 
     1/* NeXus - Neutron & X-ray Common Data Format 
     2 * 
     3 * NeXus file validation GUI tool. 
     4 * 
     5 * Copyright (C) 2010 Stephen Rankin 
     6 * 
     7 * This library is free software; you can redistribute it and/or 
     8 * modify it under the terms of the GNU Lesser General Public 
     9 * License as published by the Free Software Foundation; either 
     10 * version 2 of the License, or (at your option) any later version. 
     11 * 
     12 * This library is distributed in the hope that it will be useful, 
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     15 * Lesser General Public License for more details. 
     16 * 
     17 * You should have received a copy of the GNU Lesser General Public 
     18 * License along with this library; if not, write to the Free Software 
     19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     20 * 
     21 * For further information, see <http://www.neutron.anl.gov/NeXus/> 
     22 * 
     23 * NXNodeMapper.java 
     24 * 
    425 */ 
    526package org.nexusformat.nxvalidate; 
     
    1233import javax.swing.tree.TreeNode; 
    1334import org.w3c.dom.Document; 
     35import org.w3c.dom.Element; 
    1436import org.w3c.dom.NamedNodeMap; 
    1537import org.w3c.dom.Node; 
     
    2244public class NXNodeMapper implements MutableTreeNode { 
    2345 
    24     Node domNode = null; 
     46    private Node domNode = null; 
    2547    private String nodeName = null; 
    2648    private boolean isRoot = false; 
     
    80102    } 
    81103 
     104    /** 
     105     * Check to see if this node is the root node. 
     106     * @return true is it is the root node, false otherwise. 
     107     */ 
    82108    public boolean isRoot() { 
    83109        return isRoot; 
    84110    } 
    85111 
     112    /** 
     113     * Check to see if this node is a document, i.e the list of nodes directly 
     114     * under the root note that are the open NXS documents. 
     115     * 
     116     * @return true if the node is a document node. 
     117     */ 
    86118    public boolean isDocument() { 
    87119        return isDocument; 
    88120    } 
    89121 
     122    /** 
     123     * Set the flag that says that this node is a documents node i.e. one of the 
     124     * list of nodes directly under the root note that are the open NXS documents. 
     125     * @param isDocument a flag which is true if the node is a document node. 
     126     */ 
    90127    public void setDocument(boolean isDocument) { 
    91128        this.isDocument = isDocument; 
    92129    } 
    93130 
     131    /** 
     132     * Set the root node that this node belongs to. 
     133     * @param the root node. 
     134     */ 
    94135    public void setRoot(NXNodeMapper root) { 
    95136        this.root = root; 
    96137    } 
    97138 
    98     public void insert(NXNodeMapper node) { 
     139    /*public void insert(NXNodeMapper node) { 
    99140        documents.add(node); 
    100     } 
    101  
    102     public void removeNode(NXNodeMapper node) { 
    103         if (!isRoot) { 
    104             documents.remove(node); 
    105         } 
    106     } 
     141    }*/ 
    107142 
    108143    public File getNXSFile() { 
     
    156191    public boolean getBadNode() { 
    157192        return badNode; 
     193    } 
     194 
     195    public Node getDomNode() { 
     196        return domNode; 
    158197    } 
    159198 
     
    272311 
    273312        } 
     313 
    274314        return childCount; 
    275315 
     
    413453 
    414454    public void insert(MutableTreeNode child, int index) { 
    415         if (isRoot) { 
    416  
    417             documents.add(index, (NXNodeMapper) child); 
    418  
     455 
     456        NXNodeMapper childNode = (NXNodeMapper) child; 
     457 
     458        if (isRoot) { 
     459            documents.add(index, childNode); 
     460        } else{ 
     461            NodeList list = domNode.getChildNodes(); 
     462 
     463            for (int i = 0; i < list.getLength(); ++i) { 
     464                if(i == index){ 
     465                    domNode.insertBefore(childNode.domNode, list.item(i)); 
     466                } 
     467            } 
    419468        } 
    420469    } 
     
    425474            documents.remove(index); 
    426475 
     476        } else{ 
     477 
     478            NodeList list = domNode.getChildNodes(); 
     479 
     480            for (int i = 0; i < list.getLength(); ++i) { 
     481                if(i == index){ 
     482                    domNode.removeChild(list.item(index)); 
     483                } 
     484            } 
     485 
    427486        } 
    428487    } 
    429488 
    430489    public void remove(MutableTreeNode node) { 
    431         if (isRoot) { 
    432  
     490 
     491        NXNodeMapper childNode = (NXNodeMapper) node; 
     492 
     493        if (isRoot) { 
    433494            documents.remove((NXNodeMapper) node); 
    434  
     495        }else{ 
     496            NodeList list = domNode.getChildNodes(); 
     497 
     498            for (int i = 0; i < list.getLength(); ++i) { 
     499                if(list.item(i).isSameNode(childNode.domNode)){ 
     500                    domNode.removeChild(childNode.domNode); 
     501                } 
     502            } 
    435503        } 
    436504    } 
    437505 
    438506    public void removeFromParent() { 
    439         if (!isRoot) { 
    440           documents.remove(this); 
     507        if (isRoot) { 
     508           return; 
     509        } else{ 
     510           NXNodeMapper parentNode = (NXNodeMapper)getParent(); 
     511           parentNode.remove(this); 
    441512        } 
    442513    } 
Note: See TracChangeset for help on using the changeset viewer.