FileDocCategorySizeDatePackage
SortTreeDemo.javaAPI DocExample1731Thu Oct 24 20:14:26 BST 2002None

SortTreeDemo

public class SortTreeDemo extends JFrame

Fields Summary
Constructors Summary
public SortTreeDemo(String startDir)

    super("SortTreeModel Demonstration");
    setSize(300, 400);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    PrettyFile f = new PrettyFile(startDir);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(f);
    SortTreeModel model = new SortTreeModel(root, new TreeStringComparator());
    fillModel(model, root);

    JTree tree = new JTree(model);
    getContentPane().add(new JScrollPane(tree));
  
Methods Summary
protected voidfillModel(SortTreeModel model, javax.swing.tree.DefaultMutableTreeNode current)

    PrettyFile pf = (PrettyFile)current.getUserObject();
    File f = pf.getFile();
    if (f.isDirectory()) {
      String files[] = f.list();
      // ignore "." files
      for (int i = 0; i < files.length; i++) {
        if (files[i].startsWith(".")) continue;
        PrettyFile tmp = new PrettyFile(pf, files[i]);
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp);
        model.insertNodeInto(node, current);
        if (tmp.getFile().isDirectory()) {
          fillModel(model, node);
        }
      }
    }
  
public static voidmain(java.lang.String[] args)

    SortTreeDemo demo = new SortTreeDemo(args.length == 1 ? args[0] : ".");
    demo.setVisible(true);