home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / SynchronizerNode.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  2.7 KB  |  97 lines

  1. /**
  2.  * @(#)SynchronizerNode.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. package symantec.itools.db.beans.binding;
  9.  
  10. import javax.awt.swing.tree.DefaultMutableTreeNode;
  11. import java.util.Vector;
  12. import java.util.Enumeration;
  13.  
  14. class SynchronizerNode extends DefaultMutableTreeNode
  15. {
  16.     // Enumeration types
  17.  
  18.     /**
  19.      * Enumerate tree nodes from top to bottom including the top.
  20.      */
  21.     final static int TOP_DOWN_INCLUSIVE = 0;
  22.  
  23.     /**
  24.      * Enumerate tree nodes from top to bottom excluding the top.
  25.      */
  26.     final static int TOP_DOWN_EXCLUSIVE = 1;
  27.  
  28.     /**
  29.      * Enumerate tree nodes from bottom to top
  30.      */
  31.     final static int BOTTOM_UP = 2;
  32.  
  33.     /**
  34.      * Enumerate current node only
  35.      */
  36.     final static int CURRENT_NODE_ONLY = 3;
  37.  
  38.     /**
  39.      * Create an enumeration from the given node.
  40.      * The enumeration can be top-down or bottom-up
  41.      */
  42.  
  43.     Enumeration enumerateNodes(int enumerationType)
  44.     {
  45.         Enumeration enum;
  46.  
  47.         if (isLeaf()) {
  48.             return getSimpleEnumeration(enumerationType);
  49.         }
  50.  
  51.         switch (enumerationType) {
  52.             case TOP_DOWN_INCLUSIVE:
  53.                 enum = preorderEnumeration();
  54.                 break;
  55.             case TOP_DOWN_EXCLUSIVE:
  56.                 enum = preorderEnumeration();
  57.                 enum.nextElement(); // exclude first node
  58.                 break;
  59.             case BOTTOM_UP:  // exclusive of first node
  60.                 enum = postorderEnumeration();
  61.                 Vector temp = new Vector();
  62.                 int index = 0;
  63.                 for (index = 0; enum.hasMoreElements(); index++) {
  64.                     temp.addElement(enum.nextElement());
  65.                 }
  66.                 temp.removeElementAt(index -1);
  67.                 enum = temp.elements();
  68.                 break;
  69.             case CURRENT_NODE_ONLY:
  70.             default:
  71.                 temp = new Vector();
  72.                 temp.addElement(this);
  73.                 enum = temp.elements();
  74.                 break;
  75.         }
  76.  
  77.         return enum;
  78.     }
  79.  
  80.     Enumeration getSimpleEnumeration(int enumerationType)
  81.     {
  82.         Vector temp = new Vector();
  83.         switch(enumerationType) {
  84.             case TOP_DOWN_INCLUSIVE:        // inclusive
  85.             case CURRENT_NODE_ONLY:         // inclusive
  86.                 temp.addElement(this);
  87.                 break;
  88.             case TOP_DOWN_EXCLUSIVE:        // exclusive
  89.             case BOTTOM_UP:                 // exclusive
  90.             default:                        // exclusive
  91.                 break;
  92.         }
  93.  
  94.         return temp.elements();
  95.     }
  96.     
  97. };