KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > SheetColumnModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * SheetTableModel.java
21  *
22  * Created on December 13, 2002, 6:14 PM
23  */

24 package org.openide.explorer.propertysheet;
25
26 import java.util.Enumeration JavaDoc;
27
28 import javax.swing.*;
29 import javax.swing.event.*;
30 import javax.swing.table.*;
31
32
33 /** Column model for the property sheet table. This class primarily exists because
34  * dragging to move the center line of the table is much faster without a
35  * DefaultTableColumnModel firing spurious change events while dragging.
36  *
37  * @author Tim Boudreau
38  */

39 final class SheetColumnModel implements TableColumnModel {
40     static final Object JavaDoc NAMES_IDENTIFIER = "names"; //NOI18N
41
static final Object JavaDoc VALUES_IDENTIFIER = "values"; //NOI18N
42
TableColumn namesColumn;
43     TableColumn valuesColumn;
44     ListSelectionModel lsm = new DefaultListSelectionModel();
45
46     /** Creates a new instance of SheetTableModel */
47     public SheetColumnModel() {
48         namesColumn = new TableColumn(0);
49         namesColumn.setIdentifier(NAMES_IDENTIFIER);
50         valuesColumn = new TableColumn(1);
51         valuesColumn.setIdentifier(VALUES_IDENTIFIER);
52         namesColumn.setMinWidth(60);
53         valuesColumn.setMinWidth(30);
54     }
55
56     public void addColumn(TableColumn aColumn) {
57         throw new UnsupportedOperationException JavaDoc("Adding columns not supported"); //NOI18N
58
}
59
60     public void addColumnModelListener(TableColumnModelListener x) {
61         //do nothing - no events wil happen
62
}
63
64     public TableColumn getColumn(int columnIndex) {
65         switch (columnIndex) {
66         case 0:
67             return namesColumn;
68
69         case 1:
70             return valuesColumn;
71         }
72
73         throw new IllegalArgumentException JavaDoc("Property sheet only has 2 columns - " + Integer.toString(columnIndex)); //NOI18N
74
}
75
76     public int getColumnCount() {
77         return 2;
78     }
79
80     public int getColumnIndex(Object JavaDoc columnIdentifier) {
81         if (columnIdentifier instanceof String JavaDoc) {
82             if (columnIdentifier.equals(NAMES_IDENTIFIER)) {
83                 return 0;
84             }
85
86             if (columnIdentifier.equals(VALUES_IDENTIFIER)) {
87                 return 1;
88             }
89         }
90
91         throw new IllegalArgumentException JavaDoc("Illegal value: " + columnIdentifier);
92     }
93
94     public int getColumnIndexAtX(int xPosition) {
95         int width0 = namesColumn.getWidth();
96
97         if (xPosition < width0) {
98             return 0;
99         }
100
101         if (xPosition < (width0 + valuesColumn.getWidth())) {
102             return 1;
103         }
104
105         return -1;
106     }
107
108     public int getColumnMargin() {
109         return 1; //XXX fix
110
}
111
112     public boolean getColumnSelectionAllowed() {
113         return false;
114     }
115
116     public Enumeration JavaDoc<TableColumn> getColumns() {
117         return new Enumeration JavaDoc<TableColumn>() {
118                 private boolean done = false;
119                 private boolean doneOne = false;
120
121                 public boolean hasMoreElements() {
122                     return !done;
123                 }
124
125                 public TableColumn nextElement() {
126                     if (done) {
127                         return null;
128                     }
129
130                     if (doneOne) {
131                         done = true;
132
133                         return valuesColumn;
134                     }
135
136                     doneOne = true;
137
138                     return namesColumn;
139                 }
140             };
141     }
142
143     public int getSelectedColumnCount() {
144         return 0;
145     }
146
147     public int[] getSelectedColumns() {
148         return new int[] { };
149     }
150
151     public ListSelectionModel getSelectionModel() {
152         return lsm;
153     }
154
155     public int getTotalColumnWidth() {
156         return namesColumn.getWidth() + valuesColumn.getWidth();
157     }
158
159     public void moveColumn(int columnIndex, int newIndex) {
160         //do nothing
161
}
162
163     public void removeColumn(TableColumn column) {
164         throw new UnsupportedOperationException JavaDoc("Deleting columns not supported"); //NOI18N
165
}
166
167     public void removeColumnModelListener(TableColumnModelListener x) {
168         //do nothing, columns will not change
169
}
170
171     public void setColumnMargin(int newMargin) {
172         //do nothing, unsupported
173
}
174
175     public void setColumnSelectionAllowed(boolean flag) {
176         //do nothing, unsupported
177
}
178
179     public void setSelectionModel(ListSelectionModel newModel) {
180         //do nothing, unsupported
181
}
182 }
183
Popular Tags