00001 package edu.ksu.cis.bandera.abstraction.gui;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import javax.swing.tree.*;
00018 import javax.swing.event.*;
00019
00020
00021
00022
00023
00024
00025
00026
00027 public abstract class AbstractTreeTableModel extends DefaultTreeModel implements TreeTableModel {
00028 protected AbstractTreeNode root;
00029 protected EventListenerList listenerList = new EventListenerList();
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 public AbstractTreeTableModel(AbstractTreeNode root) {
00040 super(root);
00041 this.root = root;
00042 }
00043 public void addTreeModelListener(TreeModelListener l) {
00044 listenerList.add(TreeModelListener.class, l);
00045 }
00046
00047
00048
00049
00050
00051
00052
00053 protected void fireTreeNodesChanged(Object source, Object[] path,
00054 int[] childIndices,
00055 Object[] children) {
00056
00057 Object[] listeners = listenerList.getListenerList();
00058 TreeModelEvent e = null;
00059
00060
00061 for (int i = listeners.length-2; i>=0; i-=2) {
00062 if (listeners[i]==TreeModelListener.class) {
00063
00064 if (e == null)
00065 e = new TreeModelEvent(source, path,
00066 childIndices, children);
00067 ((TreeModelListener)listeners[i+1]).treeNodesChanged(e);
00068 }
00069 }
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 protected void fireTreeNodesInserted(Object source, Object[] path,
00079 int[] childIndices,
00080 Object[] children) {
00081
00082 Object[] listeners = listenerList.getListenerList();
00083 TreeModelEvent e = null;
00084
00085
00086 for (int i = listeners.length-2; i>=0; i-=2) {
00087 if (listeners[i]==TreeModelListener.class) {
00088
00089 if (e == null)
00090 e = new TreeModelEvent(source, path,
00091 childIndices, children);
00092 ((TreeModelListener)listeners[i+1]).treeNodesInserted(e);
00093 }
00094 }
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 protected void fireTreeNodesRemoved(Object source, Object[] path,
00104 int[] childIndices,
00105 Object[] children) {
00106
00107 Object[] listeners = listenerList.getListenerList();
00108 TreeModelEvent e = null;
00109
00110
00111 for (int i = listeners.length-2; i>=0; i-=2) {
00112 if (listeners[i]==TreeModelListener.class) {
00113
00114 if (e == null)
00115 e = new TreeModelEvent(source, path,
00116 childIndices, children);
00117 ((TreeModelListener)listeners[i+1]).treeNodesRemoved(e);
00118 }
00119 }
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 protected void fireTreeStructureChanged(Object source, Object[] path,
00129 int[] childIndices,
00130 Object[] children) {
00131
00132 Object[] listeners = listenerList.getListenerList();
00133 TreeModelEvent e = null;
00134
00135
00136 for (int i = listeners.length-2; i>=0; i-=2) {
00137 if (listeners[i]==TreeModelListener.class) {
00138
00139 if (e == null)
00140 e = new TreeModelEvent(source, path,
00141 childIndices, children);
00142 ((TreeModelListener)listeners[i+1]).treeStructureChanged(e);
00143 }
00144 }
00145 }
00146
00147
00148
00149
00150 public Class getColumnClass(int column) {
00151 return Object.class;
00152 }
00153
00154 public int getIndexOfChild(Object parent, Object child) {
00155 for (int i = 0; i < getChildCount(parent); i++) {
00156 if (getChild(parent, i).equals(child)) {
00157 return i;
00158 }
00159 }
00160 return -1;
00161 }
00162
00163
00164
00165
00166 public Object getRoot() {
00167 return root;
00168 }
00169
00170
00171
00172
00173 public boolean isCellEditable(Object node, int column) {
00174 return getColumnClass(column) == TreeTableModel.class;
00175 }
00176 public boolean isLeaf(Object node) {
00177 return getChildCount(node) == 0;
00178 }
00179 public void removeTreeModelListener(TreeModelListener l) {
00180 listenerList.remove(TreeModelListener.class, l);
00181 }
00182
00183
00184
00185
00186
00187 public void setRoot(AbstractTreeNode root) {
00188 this.root = root;
00189 }
00190 public void setValueAt(Object aValue, Object node, int column) {}
00191 public void valueForPathChanged(TreePath path, Object newValue) {}
00192 }