KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > table > DefaultTableColumnModel


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: DefaultTableColumnModel.java,v $
11    Revision 1.6 2004/04/16 10:19:07 dannaab
12    Misc bug fixes, InputMap implementation, preliminary undo support
13
14    Revision 1.5 2004/04/15 11:24:33 bobintetley
15    (Dan Naab) ComponentUI, UIDefaults/UIManager and Accessibility support.
16    (Antonio Weber) TableColumnModelListener implementation and support
17
18    Revision 1.4 2003/12/17 10:57:35 bobintetley
19    JTableHeader implementation plus Table event/model fixes
20
21    Revision 1.3 2003/12/14 09:13:39 bobintetley
22    Added CVS log to source headers
23
24 */

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     /** This is a real cheat! Because we can't work out X position
40      * accurately, I'm going to assume that when somebody calls
41      * getColumnIndexAtX, they really want the column the mouse
42      * was over last. Since I do have that info, I set it here
43      * and return it for getColumnIndexAtX
44      */

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 JavaDoc 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 JavaDoc("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