home *** CD-ROM | disk | FTP | other *** search
/ Datatid 2000 #1 / Datatid-2000-01.iso / Internet / JAVA_NAVIGATOR / JAVANAVIGATOR.EXE / %MAINDIR% / files / JClass / TreeNode.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-31  |  2.0 KB  |  87 lines

  1. import java.awt.Image;
  2.  
  3. public class TreeNode {
  4.    TreeNode sibling;
  5.    TreeNode child;
  6.    TreeNode parent;
  7.    String text;
  8.    Image collapsedImage;
  9.    Image expandedImage;
  10.    int depth;
  11.    boolean isExpanded;
  12.    int numberOfChildren;
  13.  
  14.    public TreeNode(String text) {
  15.       this(text, (Image)null, (Image)null);
  16.    }
  17.  
  18.    public TreeNode(String text, Image collapsedImage, Image expandedImage) {
  19.       this.depth = -1;
  20.       this.isExpanded = false;
  21.       this.text = text;
  22.       this.sibling = null;
  23.       this.child = null;
  24.       this.collapsedImage = collapsedImage;
  25.       this.expandedImage = expandedImage;
  26.       this.numberOfChildren = 0;
  27.    }
  28.  
  29.    void setDepth(int depth) {
  30.       this.depth = depth;
  31.    }
  32.  
  33.    public int getDepth() {
  34.       return this.depth;
  35.    }
  36.  
  37.    public boolean isExpanded() {
  38.       return this.isExpanded;
  39.    }
  40.  
  41.    public boolean isExpandable() {
  42.       return this.child != null;
  43.    }
  44.  
  45.    public void expand() {
  46.       if (this.isExpandable()) {
  47.          this.isExpanded = true;
  48.       }
  49.  
  50.    }
  51.  
  52.    public void collapse() {
  53.       this.isExpanded = false;
  54.    }
  55.  
  56.    public void toggle() {
  57.       if (this.isExpanded) {
  58.          this.collapse();
  59.       } else {
  60.          if (this.isExpandable()) {
  61.             this.expand();
  62.          }
  63.  
  64.       }
  65.    }
  66.  
  67.    public Image getImage() {
  68.       return this.isExpanded && this.expandedImage != null ? this.expandedImage : this.collapsedImage;
  69.    }
  70.  
  71.    public void setExpandedImage(Image image) {
  72.       this.expandedImage = image;
  73.    }
  74.  
  75.    public void setCollapsedImage(Image image) {
  76.       this.collapsedImage = image;
  77.    }
  78.  
  79.    public String getText() {
  80.       return this.text;
  81.    }
  82.  
  83.    public void setText(String s) {
  84.       this.text = new String(s);
  85.    }
  86. }
  87.