src/main/java/pl/net/lkd/TagTools/Viewer/TreeViewer.java
/**
   * This main() method demonstrates the use of this class, the use of the
   * Xerces DOM parser, and the creation of a DOM Level 2 TreeWalker object.
   */
This main() method demonstrates the use of this class, the use of the
Xerces DOM parser, and the creation of a DOM Level 2 TreeWalker object.
This main () method demonstrates the use of this class the use of the Xerces DOM parser and the creation of a DOM Level 2 TreeWalker object .
public static void main(Document d) throws IOException, SAXException
  {
    Document document = d;
    DocumentTraversal traversal = (DocumentTraversal) document;
    NodeFilter filter = new NodeFilter()
    {
      public short acceptNode(Node n)
      {
        if (n.getNodeType() == Node.TEXT_NODE)
        {
          if (((Text) n).getData().trim().length() == 0)
          {
            return NodeFilter.FILTER_REJECT;
          }
        }
        return NodeFilter.FILTER_ACCEPT;
      }
    };
    int whatToShow = NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_COMMENT;
    TreeWalker walker = traversal.createTreeWalker(document, whatToShow,
            filter, false);
    JTree tree = new JTree(new TreeViewer(walker));
    JFrame frame = new JFrame("DOMTreeWalkerTreeModel Demo");
    frame.getContentPane().add(new JScrollPane(tree));
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });
    frame.setSize(500, 250);
    frame.setVisible(true);
  }
public static void main ( Document d ) throws IOException , SAXException { Document document = d ; DocumentTraversal traversal = ( DocumentTraversal ) document ; NodeFilter filter = new NodeFilter ( ) { public short acceptNode ( Node n ) { if ( n . getNodeType ( ) == Node . TEXT_NODE ) { if ( ( ( Text ) n ) . getData ( ) . trim ( ) . length ( ) == 0 ) { return NodeFilter . FILTER_REJECT ; } } return NodeFilter . FILTER_ACCEPT ; } } ; int whatToShow = NodeFilter . SHOW_ALL & ~ NodeFilter . SHOW_COMMENT ; TreeWalker walker = traversal . createTreeWalker ( document , whatToShow , filter , false ) ; JTree tree = new JTree ( new TreeViewer ( walker ) ) ; JFrame frame = new JFrame ( "DOMTreeWalkerTreeModel Demo" ) ; frame . getContentPane ( ) . add ( new JScrollPane ( tree ) ) ; frame . addWindowListener ( new WindowAdapter ( ) { public void windowClosing ( WindowEvent e ) { System . exit ( 0 ) ; } } ) ; frame . setSize ( 500 , 250 ) ; frame . setVisible ( true ) ; }
This main() method demonstrates the use of this class, the use of the
 Xerces DOM parser, and the creation of a DOM Level 2 TreeWalker object.
This main () method demonstrates the use of this class the use of the Xerces DOM parser and the creation of a DOM Level 2 TreeWalker object .
// If we're using a DOM Level 2 implementation, then our Document // object ought to implement DocumentTraversal // For this demonstration, we create a NodeFilter that filters out // Text nodes containing only space; these just clutter up the tree // Use trim() to strip off leading and trailing space. // If nothing is left, then reject the node // This set of flags says to "show" all node types except comments // Create a TreeWalker using the filter and the flags // Instantiate a TreeModel and a JTree to display it // Create a frame and a scrollpane to display the tree, and pop them up