• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.hierarchyviewer.ui.model;
18 
19 import com.android.hierarchyviewer.scene.ViewNode;
20 
21 import javax.swing.tree.TreeModel;
22 import javax.swing.tree.TreePath;
23 import javax.swing.event.TreeModelListener;
24 
25 public class ViewsTreeModel implements TreeModel {
26     private final ViewNode root;
27 
ViewsTreeModel(ViewNode root)28     public ViewsTreeModel(ViewNode root) {
29         this.root = root;
30     }
31 
getRoot()32     public Object getRoot() {
33         return root;
34     }
35 
getChild(Object o, int i)36     public Object getChild(Object o, int i) {
37         return ((ViewNode) o).children.get(i);
38     }
39 
getChildCount(Object o)40     public int getChildCount(Object o) {
41         return ((ViewNode) o).children.size();
42     }
43 
isLeaf(Object child)44     public boolean isLeaf(Object child) {
45         ViewNode node = (ViewNode) child;
46         return node.children == null || node.children.size() == 0;
47     }
48 
valueForPathChanged(TreePath treePath, Object child)49     public void valueForPathChanged(TreePath treePath, Object child) {
50     }
51 
getIndexOfChild(Object parent, Object child)52     public int getIndexOfChild(Object parent, Object child) {
53         //noinspection SuspiciousMethodCalls
54         return ((ViewNode) parent).children.indexOf(child);
55     }
56 
addTreeModelListener(TreeModelListener treeModelListener)57     public void addTreeModelListener(TreeModelListener treeModelListener) {
58     }
59 
removeTreeModelListener(TreeModelListener treeModelListener)60     public void removeTreeModelListener(TreeModelListener treeModelListener) {
61     }
62 }
63