1 package prefuse.data.util; 2 3 import prefuse.data.CascadedTable; 4 import prefuse.data.Table; 5 import prefuse.data.column.IntColumn; 6 import prefuse.util.collections.IntIntSortedMap; 7 import prefuse.util.collections.IntIntTreeMap; 8 9 15 public class FilteredRowManager extends RowManager { 16 17 protected IntColumn m_childToParent; 18 protected IntIntSortedMap m_parentToChild; 19 20 24 public FilteredRowManager(Table table) { 25 super(table); 26 m_childToParent = new IntColumn(table.getRowCount()); 27 m_parentToChild = new IntIntTreeMap(false); 28 clear(); 29 } 30 31 34 public void clear() { 35 super.clear(); 36 m_parentToChild.clear(); 37 for ( int i=0; i<m_childToParent.getRowCount(); ++i ) { 38 m_childToParent.setInt(-1, i); 39 } 40 } 41 42 47 public int addRow(int parentRow) { 48 int r = super.addRow(); 49 put(r, parentRow); 50 return r; 51 } 52 53 56 public boolean releaseRow(int row) { 57 if ( super.releaseRow(row) ) { 58 remove(row); 59 return true; 60 } else { 61 return false; 62 } 63 } 64 65 68 public int getColumnRow(int row, int col) { 69 return ((CascadedTable)m_table).getParentTable() 70 .getColumnRow(getParentRow(row), col); 71 } 72 73 76 public int getTableRow(int columnRow, int col) { 77 return getChildRow(columnRow); 78 } 79 80 82 88 public int getParentRow(int childRow) { 89 if ( childRow >= m_childToParent.getRowCount() ) { 90 return -1; 91 } else { 92 return m_childToParent.getInt(childRow); 93 } 94 } 95 96 102 public int getChildRow(int parentRow) { 103 int val = m_parentToChild.get(parentRow); 104 return ( val == Integer.MIN_VALUE ? -1 : val ); 105 } 106 107 112 public void put(int childRow, int parentRow) { 113 if ( childRow >= m_childToParent.getRowCount() ) 115 m_childToParent.setMaximumRow(childRow+1); 116 117 m_childToParent.setInt(parentRow, childRow); 119 m_parentToChild.put(parentRow, childRow); 120 } 121 122 127 public void remove(int childRow) { 128 int parentRow = m_childToParent.getInt(childRow); 129 m_childToParent.setInt(-1, childRow); 130 m_parentToChild.remove(parentRow); 131 } 132 133 } | Popular Tags |