1 20 33 34 package com.puppycrawl.tools.checkstyle.gui; 35 36 import javax.swing.tree.*; 37 import javax.swing.event.*; 38 39 45 46 public abstract class AbstractTreeTableModel implements TreeTableModel 47 { 48 private Object mRoot; 49 private final EventListenerList mListenerList = new EventListenerList(); 50 51 public AbstractTreeTableModel(Object root) 52 { 53 this.mRoot = root; 54 } 55 56 60 public Object getRoot() 61 { 62 return mRoot; 63 } 64 65 public boolean isLeaf(Object node) 66 { 67 return getChildCount(node) == 0; 68 } 69 70 public void valueForPathChanged(TreePath path, Object newValue) 71 { 72 } 73 74 public int getIndexOfChild(Object parent, Object child) 76 { 77 for (int i = 0; i < getChildCount(parent); i++) { 78 if (getChild(parent, i).equals(child)) { 79 return i; 80 } 81 } 82 return -1; 83 } 84 85 public void addTreeModelListener(TreeModelListener l) 86 { 87 mListenerList.add(TreeModelListener.class, l); 88 } 89 90 public void removeTreeModelListener(TreeModelListener l) 91 { 92 mListenerList.remove(TreeModelListener.class, l); 93 } 94 95 102 protected void fireTreeNodesChanged(Object source, Object [] path, 103 int[] childIndices, 104 Object [] children) 105 { 106 final Object [] listeners = mListenerList.getListenerList(); 108 TreeModelEvent e = null; 109 for (int i = listeners.length - 2; i >= 0; i -= 2) { 112 if (listeners[i] == TreeModelListener.class) { 113 if (e == null) 115 e = new TreeModelEvent(source, path, 116 childIndices, children); 117 ((TreeModelListener) listeners[i + 1]).treeNodesChanged(e); 118 } 119 } 120 } 121 122 129 protected void fireTreeNodesInserted(Object source, Object [] path, 130 int[] childIndices, 131 Object [] children) 132 { 133 final Object [] listeners = mListenerList.getListenerList(); 135 TreeModelEvent e = null; 136 for (int i = listeners.length - 2; i >= 0; i -= 2) { 139 if (listeners[i] == TreeModelListener.class) { 140 if (e == null) 142 e = new TreeModelEvent(source, path, 143 childIndices, children); 144 ((TreeModelListener) listeners[i + 1]).treeNodesInserted(e); 145 } 146 } 147 } 148 149 156 protected void fireTreeNodesRemoved(Object source, Object [] path, 157 int[] childIndices, 158 Object [] children) 159 { 160 final Object [] listeners = mListenerList.getListenerList(); 162 TreeModelEvent e = null; 163 for (int i = listeners.length - 2; i >= 0; i -= 2) { 166 if (listeners[i] == TreeModelListener.class) { 167 if (e == null) 169 e = new TreeModelEvent(source, path, 170 childIndices, children); 171 ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e); 172 } 173 } 174 } 175 176 183 protected void fireTreeStructureChanged(Object source, Object [] path, 184 int[] childIndices, 185 Object [] children) 186 { 187 final Object [] listeners = mListenerList.getListenerList(); 189 TreeModelEvent e = null; 190 for (int i = listeners.length - 2; i >= 0; i -= 2) { 193 if (listeners[i] == TreeModelListener.class) { 194 if (e == null) 196 e = new TreeModelEvent(source, path, 197 childIndices, children); 198 ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e); 199 } 200 } 201 } 202 203 207 public Class getColumnClass(int column) 208 { 209 return Object .class; 210 } 211 212 216 public boolean isCellEditable(Object node, int column) 217 { 218 return getColumnClass(column) == TreeTableModel.class; 219 } 220 221 public void setValueAt(Object aValue, Object node, int column) 222 { 223 } 224 225 226 228 235 } 236 | Popular Tags |