1 22 23 package salsa.debug; 24 25 import java.awt.*; 26 import javax.swing.*; 27 import javax.swing.event.*; 28 import javax.swing.tree.*; 29 30 public class ComponentTreeModel implements TreeModel 31 { 32 Component _root; 33 34 public ComponentTreeModel( Component root ) 35 { 36 _root = root; 37 } 38 39 public Object getChild( Object parent, int index ) 40 { 41 if( parent instanceof Container ) 42 { 43 return ( ( Container ) parent ).getComponent( index ); 44 } 45 return null; 46 } 47 48 public int getChildCount( Object obj ) 49 { 50 if( obj instanceof Container ) 51 return ( ( Container ) obj ).getComponentCount(); 52 return 0; 53 } 54 55 public int getIndexOfChild( Object parent, Object child ) 56 { 57 if( !( parent instanceof Container ) ) 58 return -1; 59 60 Container c = ( Container ) parent; 61 Component children[] = c.getComponents(); 62 if( children == null ) 63 return -1; 64 65 for( int i = 0; i < children.length; i++ ) 66 if( children[i] == child ) 67 return i; 68 69 return -1; 70 } 71 72 public Object getRoot() 73 { 74 return _root; 75 } 76 77 public boolean isLeaf( Object obj ) 78 { 79 if( !( obj instanceof Container ) ) 80 return true; 81 82 return ( ( Container ) obj ).getComponentCount() == 0; 83 } 84 85 public void addTreeModelListener( TreeModelListener l ) { } 86 87 public void removeTreeModelListener( TreeModelListener l ) { } 88 89 public void valueForPathChanged( TreePath path, Object newValue ) { } 90 } 91 | Popular Tags |