home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / main.bin / TreeNode.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-04  |  2.6 KB  |  111 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Image;
  4.  
  5. public strictfp class TreeNode {
  6.    TreeNode sibling;
  7.    TreeNode child;
  8.    TreeNode parent;
  9.    String text;
  10.    Image collapsedImage;
  11.    Image expandedImage;
  12.    int numberOfChildren;
  13.    Object dataObject;
  14.    int depth;
  15.    boolean isExpanded;
  16.  
  17.    public TreeNode(String text) {
  18.       this(text, (Image)null, (Image)null);
  19.    }
  20.  
  21.    public TreeNode(String text, Image collapsedImage, Image expandedImage) {
  22.       this.depth = -1;
  23.       this.isExpanded = false;
  24.       this.text = text;
  25.       this.sibling = null;
  26.       this.child = null;
  27.       this.collapsedImage = collapsedImage;
  28.       this.expandedImage = expandedImage;
  29.       this.numberOfChildren = 0;
  30.       this.dataObject = null;
  31.    }
  32.  
  33.    void setDepth(int depth) {
  34.       this.depth = depth;
  35.    }
  36.  
  37.    public int getDepth() {
  38.       return this.depth;
  39.    }
  40.  
  41.    public boolean isExpanded() {
  42.       return this.isExpanded;
  43.    }
  44.  
  45.    public boolean isExpandable() {
  46.       return this.child != null;
  47.    }
  48.  
  49.    public void expand() {
  50.       if (this.isExpandable()) {
  51.          this.isExpanded = true;
  52.       }
  53.  
  54.    }
  55.  
  56.    public void collapse() {
  57.       this.isExpanded = false;
  58.    }
  59.  
  60.    public void toggle() {
  61.       if (this.isExpanded) {
  62.          this.collapse();
  63.       } else {
  64.          if (this.isExpandable()) {
  65.             this.expand();
  66.          }
  67.  
  68.       }
  69.    }
  70.  
  71.    public Image getImage() {
  72.       return this.isExpanded && this.expandedImage != null ? this.expandedImage : this.collapsedImage;
  73.    }
  74.  
  75.    public void setExpandedImage(Image image) {
  76.       this.expandedImage = image;
  77.    }
  78.  
  79.    public void setCollapsedImage(Image image) {
  80.       this.collapsedImage = image;
  81.    }
  82.  
  83.    public String getText() {
  84.       return this.text;
  85.    }
  86.  
  87.    public void setText(String s) {
  88.       this.text = new String(s);
  89.    }
  90.  
  91.    public Object getDataObject() {
  92.       return this.dataObject;
  93.    }
  94.  
  95.    public void setDataObject(Object theObject) {
  96.       this.dataObject = theObject;
  97.    }
  98.  
  99.    public TreeNode getParent() {
  100.       return this.parent;
  101.    }
  102.  
  103.    public TreeNode getChild() {
  104.       return this.child;
  105.    }
  106.  
  107.    public TreeNode getSibling() {
  108.       return this.sibling;
  109.    }
  110. }
  111.