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.table.DefaultTableModel; 22 import java.util.List; 23 import java.util.ArrayList; 24 25 public class PropertiesTableModel extends DefaultTableModel { 26 private List<ViewNode.Property> properties; 27 private List<ViewNode.Property> privateProperties = new ArrayList<ViewNode.Property>(); 28 29 public PropertiesTableModel(ViewNode node) { 30 properties = node.properties; 31 loadPrivateProperties(node); 32 } 33 34 private void loadPrivateProperties(ViewNode node) { 35 int x = node.left; 36 int y = node.top; 37 ViewNode p = node.parent; 38 while (p != null) { 39 x += p.left - p.scrollX; 40 y += p.top - p.scrollY; 41 p = p.parent; 42 } 43 44 ViewNode.Property property = new ViewNode.Property(); 45 property.name = "absolute_x"; 46 property.value = String.valueOf(x); 47 privateProperties.add(property); 48 49 property = new ViewNode.Property(); 50 property.name = "absolute_y"; 51 property.value = String.valueOf(y); 52 privateProperties.add(property); 53 } 54 55 @Override 56 public int getRowCount() { 57 return (privateProperties == null ? 0 : privateProperties.size()) + 58 (properties == null ? 0 : properties.size()); 59 } 60 61 @Override 62 public Object getValueAt(int row, int column) { 63 ViewNode.Property property; 64 65 if (row < privateProperties.size()) { 66 property = privateProperties.get(row); 67 } else { 68 property = properties.get(row - privateProperties.size()); 69 } 70 71 return column == 0 ? property.name : property.value; 72 } 73 74 @Override 75 public int getColumnCount() { 76 return 2; 77 } 78 79 @Override 80 public String getColumnName(int column) { 81 return column == 0 ? "Property" : "Value"; 82 } 83 84 @Override 85 public boolean isCellEditable(int arg0, int arg1) { 86 return false; 87 } 88 89 @Override 90 public void setValueAt(Object arg0, int arg1, int arg2) { 91 } 92 } 93