2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.hierarchyviewer.ui.model;
19 import com.android.hierarchyviewer.scene.ViewNode;
21 import javax.swing.tree.TreeModel;
22 import javax.swing.tree.TreePath;
23 import javax.swing.event.TreeModelListener;
25 public class ViewsTreeModel implements TreeModel {
26 private final ViewNode root;
28 public ViewsTreeModel(ViewNode root) {
32 public Object getRoot() {
36 public Object getChild(Object o, int i) {
37 return ((ViewNode) o).children.get(i);
40 public int getChildCount(Object o) {
41 return ((ViewNode) o).children.size();
44 public boolean isLeaf(Object child) {
45 ViewNode node = (ViewNode) child;
46 return node.children == null || node.children.size() == 0;
49 public void valueForPathChanged(TreePath treePath, Object child) {
52 public int getIndexOfChild(Object parent, Object child) {
53 //noinspection SuspiciousMethodCalls
54 return ((ViewNode) parent).children.indexOf(child);
57 public void addTreeModelListener(TreeModelListener treeModelListener) {
60 public void removeTreeModelListener(TreeModelListener treeModelListener) {