1 25 26 package swingwtx.swing.table; 27 28 import java.util.*; 29 30 import swingwtx.swing.*; 31 import swingwtx.swing.event.*; 32 33 public class DefaultTableColumnModel implements TableColumnModel { 34 35 private Vector columns = new Vector(); 36 private Vector listenerList = new Vector(); 37 private int columnMargin = 0; 38 39 45 public int lastColClicked = -1; 46 47 public DefaultTableColumnModel() { } 48 49 public void addColumn(TableColumn t) { 50 columns.add(t); 51 fireColumnAdded(new TableColumnModelEvent(this, 0, columns.indexOf(t))); 52 } 53 54 public void removeColumn(TableColumn t) { 55 columns.remove(t); 56 fireColumnRemoved(new TableColumnModelEvent(this, 0, columns.indexOf(t))); 57 } 58 59 public int getColumnCount() { 60 return columns.size(); 61 } 62 63 public TableColumn getColumn(int columnIndex) { 64 if (columnIndex == -1) return null; 65 else return (TableColumn) columns.elementAt(columnIndex); 66 } 67 68 public int getColumnIndexAtX(int xPosition) { 69 return lastColClicked; 70 } 71 72 public int getColumnIndex(Object columnIdentifier) { 73 for (int i = 0; i < columns.size(); i++) { 74 TableColumn tc = (TableColumn) columns.get(i); 75 if (tc.getIdentifier().equals(columnIdentifier)) 76 return i; 77 } 78 throw new IllegalArgumentException ("Column not found!"); 79 } 80 81 public int getColumnMargin() { 82 return 0; 83 } 84 85 public boolean getColumnSelectionAllowed() { 86 return false; 87 } 88 89 public Enumeration getColumns() { 90 return columns.elements(); 91 } 92 93 public int getSelectedColumnCount() { 94 return 0; 95 } 96 97 public int[] getSelectedColumns() { 98 return null; 99 } 100 101 public ListSelectionModel getSelectionModel() { 102 return new DefaultListSelectionModel(); 103 } 104 105 public int getTotalColumnWidth() { 106 return 0; 107 } 108 109 public void moveColumn(int columnIndex, int newIndex) { 110 } 111 112 public void setColumnSelectionAllowed(boolean flag) { 113 } 114 115 public void setSelectionModel(ListSelectionModel newModel) { 116 } 117 118 public void setColumnMargin(int newMargin) { 119 columnMargin = newMargin; 120 fireColumnMarginChanged(); 121 } 122 123 public void addColumnModelListener(TableColumnModelListener x) { 124 listenerList.add(x); 125 } 126 127 public void removeColumnModelListener(TableColumnModelListener x) { 128 listenerList.remove(x); 129 } 130 131 protected void fireColumnAdded(TableColumnModelEvent e) { 132 int size = listenerList.size(); 133 for(int i = 0; i < size; i++) { 134 ((TableColumnModelListener )listenerList.get(i)).columnAdded(e); 135 } 136 } 137 138 protected void fireColumnMarginChanged() { 139 int size = listenerList.size(); 140 for(int i = 0; i < size; i++) { 141 ((TableColumnModelListener )listenerList.get(i)).columnMarginChanged(new swingwtx.swing.event.ChangeEvent(this)); 142 } 143 } 144 145 protected void fireColumnMoved(TableColumnModelEvent e) { 146 int size = listenerList.size(); 147 for(int i = 0; i < size; i++) { 148 ((TableColumnModelListener )listenerList.get(i)).columnMoved(e); 149 } 150 } 151 152 protected void fireColumnRemoved(TableColumnModelEvent e) { 153 int size = listenerList.size(); 154 for(int i = 0; i < size; i++) { 155 ((TableColumnModelListener )listenerList.get(i)).columnRemoved(e); 156 } 157 } 158 159 protected void fireColumnSelectionChanged(ListSelectionEvent e) { 160 int size = listenerList.size(); 161 for(int i = 0; i < size; i++) { 162 ((TableColumnModelListener )listenerList.get(i)).columnSelectionChanged(e); 163 } 164 } 165 166 public void valueChanged(ListSelectionEvent e) { 167 fireColumnSelectionChanged(e); 168 } 169 170 } | Popular Tags |