KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > salsa > debug > ComponentTreeModel


1 /*
2 ** Salsa - Swing Add-On Suite
3 ** Copyright (c) 2001, 2002 by Gerald Bauer
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

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 JavaDoc getChild( Object JavaDoc 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 JavaDoc obj )
49    {
50       if( obj instanceof Container )
51          return ( ( Container ) obj ).getComponentCount();
52       return 0;
53    }
54
55    public int getIndexOfChild( Object JavaDoc parent, Object JavaDoc 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 JavaDoc getRoot()
73    {
74       return _root;
75    }
76
77    public boolean isLeaf( Object JavaDoc 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 JavaDoc newValue ) { }
90 }
91
Popular Tags