home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 2.7 KB | 97 lines |
- /**
- * @(#)SynchronizerNode.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.beans.binding;
-
- import javax.awt.swing.tree.DefaultMutableTreeNode;
- import java.util.Vector;
- import java.util.Enumeration;
-
- class SynchronizerNode extends DefaultMutableTreeNode
- {
- // Enumeration types
-
- /**
- * Enumerate tree nodes from top to bottom including the top.
- */
- final static int TOP_DOWN_INCLUSIVE = 0;
-
- /**
- * Enumerate tree nodes from top to bottom excluding the top.
- */
- final static int TOP_DOWN_EXCLUSIVE = 1;
-
- /**
- * Enumerate tree nodes from bottom to top
- */
- final static int BOTTOM_UP = 2;
-
- /**
- * Enumerate current node only
- */
- final static int CURRENT_NODE_ONLY = 3;
-
- /**
- * Create an enumeration from the given node.
- * The enumeration can be top-down or bottom-up
- */
-
- Enumeration enumerateNodes(int enumerationType)
- {
- Enumeration enum;
-
- if (isLeaf()) {
- return getSimpleEnumeration(enumerationType);
- }
-
- switch (enumerationType) {
- case TOP_DOWN_INCLUSIVE:
- enum = preorderEnumeration();
- break;
- case TOP_DOWN_EXCLUSIVE:
- enum = preorderEnumeration();
- enum.nextElement(); // exclude first node
- break;
- case BOTTOM_UP: // exclusive of first node
- enum = postorderEnumeration();
- Vector temp = new Vector();
- int index = 0;
- for (index = 0; enum.hasMoreElements(); index++) {
- temp.addElement(enum.nextElement());
- }
- temp.removeElementAt(index -1);
- enum = temp.elements();
- break;
- case CURRENT_NODE_ONLY:
- default:
- temp = new Vector();
- temp.addElement(this);
- enum = temp.elements();
- break;
- }
-
- return enum;
- }
-
- Enumeration getSimpleEnumeration(int enumerationType)
- {
- Vector temp = new Vector();
- switch(enumerationType) {
- case TOP_DOWN_INCLUSIVE: // inclusive
- case CURRENT_NODE_ONLY: // inclusive
- temp.addElement(this);
- break;
- case TOP_DOWN_EXCLUSIVE: // exclusive
- case BOTTOM_UP: // exclusive
- default: // exclusive
- break;
- }
-
- return temp.elements();
- }
-
- };